What's new

Stymied once again!

albie0803

Alibre Super User
Warning! [Rant]

Once again, scripting has frustrated me. I have a 'keyway in a shaft' script that requires the origin face (which needs to be collinear to the origin point) to be selected in order to get a distance (as I can measure from face to face but not face to plane) to put a keyway from a selected face.
I recently read the section on face and plane mapping and thought great! I can map points off the end faces of the cylinder I want the key in but map plane needs XYZ positions of points to work, not an actual point! ARRRRGH!!!:mad:

If a script can identify a face and a point and a vertex, why can't it read where they are?

My point being, if I knew where the points were, I wouldn't be trying to establish a zero point to sketch from.
[/Rant]

I DO appreciate all the effort that has gone into creating scripting, but things like this that scuttle scripting ideas just drives me nuts. Helicals is the other big one.


I had an idea for cutting a thread in any hole perpendicular to a flat face via script.
1 Select hole face > add axis
2 Select flat face > add plane1
3 Add plane2 thread depth distance below plane1
4 Create Point1 at intersection of axis and plane1
5 Create Point2 at intersection of axis and plane2
6 Create Above Axis Point
7 Use 3 points to Create Plane3 > Create sketch
8 Plane Map sketch using above 3 generated points
9 Draw tooth shape and Helical cut to depth

Steps 8&9 are not possible.
 
Last edited:
Hi Albie -- My takes is that you need an "easy way" to determine what is the "positive direction" with respect to the "face" you are "selecting." -- Lew
 

NateLiquidGravity

Alibre Super User
If a script can identify a face and a point and a vertex, why can't it read where they are?
It can - just not always a direct path.
For example:
Every face has edges and vertices.
Every edge has vertices.
Every 3d point and vertex has x, y, & z components.

There are some complex examples scripts on the support page for ideas. Specifically these:
https://support.alibre.com/support/solutions/articles/27000057884-joint-creator
https://support.alibre.com/support/solutions/articles/27000057889-pocket-hole-creator
 

NateLiquidGravity

Alibre Super User
You got me there. I'll have to look again at what info Alibre makes available with round faces and their edges. Maybe it gives center point, plane and radius - from which any point you want on the edge can be calculated.
 

idslk

Alibre Super User
Round things without corners
any point you want on the edge can be calculated
If you imagine the axis is your flagpole, and the missing third point is the wind...
Means, you can place your third point wherever you want (except on the axis) and you will get a plane "through" the axis. The direction (from where the wind blows) is normally not from interest for a thread.
Sadly the "biggest proplem" persists - the API let's you modify a helix (access to all variables...), but it is not a public function to create one
Regards
Stefan

Edit:
Added a sample part with sample script to play with (ends with the "Threadsketchplane")...
 

Attachments

  • Test_part_for_threadsketchplane.AD_PKG
    34 KB · Views: 1
Last edited:

NateLiquidGravity

Alibre Super User
@idslk That is one way to figure out that axis and plane to which to build the sketch on but if the axis is in line with the origin it fails.

@albie0803 I was right in remembering that Alibre DOES give the circular faces a single vertex. So every face will have at least 1 vertex.

So if you don't mind what direction the plane is then you could use the first vertex of the flat face regardless face shape. Replace the last two lines with:
Code:
P3 = enviroment.AddPoint('P3',startface.Vertices[0].X,startface.Vertices[0].Y,startface.Vertices[0].Z)
tsp = enviroment.AddPlane('Threadsketchplane',[P1.X,P1.Y,P1.Z],[P2.X,P2.Y,P2.Z],[P3.X,P3.Y,P3.Z])
Further to start mapping you can use those 3 points:
Code:
ts = enviroment.AddSketch("ThreadSketch", tsp)
ts.StartMapping([P1.X,P1.Y,P1.Z],[P2.X,P2.Y,P2.Z],[P3.X,P3.Y,P3.Z])
ts.AddRectangle(0, 0, 5, 10, False)
ts.StopMapping()
 
Last edited:

NateLiquidGravity

Alibre Super User
You may want to verify that the user selected a flat face for the start face and a cylinder for the cylinder face.
You may also want to know the radius of the cylinder.
Then you can put this code before the line:
startplane = enviroment.AddPlane('Startplane',startface,0)
Code:
if not str(startface._Face.Geometry.SurfaceType) == 'AD_PLANE':
    sys.exit('Exited: Selected Start Face is not flat.')
if not str(cylinderface._Face.Geometry.SurfaceType) == 'AD_CYLINDER':
    sys.exit('Exited: Selected Cylinder Face is not a Cylinder.')
radius = cylinderface._Face.Geometry.Radius # This will be in CM units by default
radius = radius * 10 # Convert to MM units to match the rest of the script. Change this if you are using a different UnitType
But as @idslk said the API does not let us make Helical features yet. I'm working on that.
 

albie0803

Alibre Super User
It was getting the mapping points from the axis crossing the cylinder faces that got me irate. In my limited knowledge it seemed unworkable. Cooler, wiser heads have kindly steered me in the right direction and I have it working. It will allow me to modify some scripts of mine that required Origin faces to work that will now have a more "user logical" flow to them.
Thanks Nate for the code snippets, I will experiment!
 

NateLiquidGravity

Alibre Super User
@albie0803 @idslk
I got Helical Cuts working by using simulated keyboard key presses. I hope Stefan is ok with me adding this on to his script. :D

I assume this will be dependent of the language of the menus so you may have to edit TUH to fit a non-English menu. Let me know how it works for you.
 

Attachments

  • Make a Helical Cut.py
    5.9 KB · Views: 10

NateLiquidGravity

Alibre Super User
Well on a different pc with v21 it gives an error when trying to select the axis with AlibreScript while the dialog is open. Worked on v22 beta o_O
 

idslk

Alibre Super User
I assume this will be dependent of the language of the menus
you're right. It might (you have to consider a lot of languages...) work, is an interesting and creative idea, but not a really clean solution for me as long as i pay maintainance and alibre is alive..., sorry.:(
Here i like to say: Alibre please complete (better: extend) the API.
That means, if i can tweak an object using the API, i should also be able to create it.
Regards
Stefan
 

NateLiquidGravity

Alibre Super User
I DEFINITELY AGREE. I've asked support to extend the API to include many things that can only be manually done. Matter of fact I asked them to just go ahead and add ALL manual abilities at once to save me time of asking for them as I need them.

This was only done in an attempt (exercise of futility) to see if it could be done (and it did work great on my testing machine).
 

idslk

Alibre Super User
(and it did work great on my testing machine)
"only for you" on my computer:
The installed AlibreScriptVersion equals 342398 as expected!
The installed AlibreVersion equals PRODUCTVERSION 21,0,2,21034 as expected!
Traceback (most recent call last):
File "<string>", line 109, in <module>
EnvironmentError: System.Runtime.InteropServices.COMException (0x8000FFFF): Das COM-Objekt des Typs "DXUTILSLib.DXContextClass" kann nicht in den Schnittstellentyp "DXUTILSLib.IDXContext" umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID "{3A93C1C0-B712-11D3-8A9E-00C04F5E8CDB}" aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Falscher Variablentyp. (Ausnahme von HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).
bei com.alibre.automation.ExceptionMap.handleException(Exception inputException)
bei com.alibre.automation.AlibreSession.Select(IObjectCollector pEntities)
bei Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
bei Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
bei Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
bei System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
bei Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
bei Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
bei Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
bei IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
bei Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
bei AlibreScript.UI.IronTextBoxControl.#P2b(Object #Dp)

"It" selects the axis, but fails on the transfer to the input window.

Regards
Stefan
 

NateLiquidGravity

Alibre Super User
Yes, that was the same error (only in English) on my pc with v21. Perhaps I'll just try running a compiled AutoHotkey script with parameters instead of attempting to do it all in AlibreScript. With AutoHotkey I won't have any COM issues.
 

NateLiquidGravity

Alibre Super User
Yeah, I still can't figure out what Alibre uses to determine direction. I first thought it had to do with only the origin however further testing showed that wasn't the only cause. But I still don't know what the other thing is. I did about 50 helical cuts in a row to test and couldn't find a reason to direction for them all.

Some other things:
As noted in the script I didn't do any realistic thread sketch. I just did a square for testing.

Radius could be used to narrow down the possible threads for the user to pick from. Since I wasn't doing that I just added thread pitch to the dialog for testing.

I haven't figured out how to determine if it's interior or exterior cylinder face. I'll probably have to test normal direction?

I noticed that it doesn't work in assemblies. I hadn't tested in assembly prior to posting it. It's unlikely that I will go through the trouble of fixing it for assemblies.
 
Top