What's new

A way to output coordintes to a *.txt file

harsimran187

New Member
A way to output coordintes to a *.txt file

Hey,
I'm new to this program, I usually use AutoCad to do all drawings. However, my boss told me to download a trial version of Alibre and test it out to see if it fits our neccessities.

I am looking for a way to take an extrusion and choose points and output these points to a text file. The application taht we use here is to model a certain die, and shape it with welders/cutters and saws. In order to do that, I need a way to find the coordinates for the xyz coordinates.

I cant really find anything to do with API's for alibre. I was wondering if someone could help me.

Thanks,
Harsimran
 

harsimran187

New Member


I've programmed this much, however the excel file does not output the coordinates. Is there anyone who can see what Im doing wrong? Or help me out?





Private Sub Command1_Click()

Dim swApp As AlibreX.AutomationHook
Dim doc As AlibreX.IADRoot
Dim part As AlibreX.IADPartSession
Dim sm As AlibreX.IADSession

Dim feat As AlibreX.IADPartFeature
Dim sketch As AlibreX.IADSketch

Dim sseg As AlibreX.IADSketchFigure
Dim sline As AlibreX.IADSketchLine
Dim sp As AlibreX.IADSketchPoint
Dim ep As AlibreX.IADSketchPoint

Dim strFilePath As String
strFilePath = "c:\\api\\sketch.AD_PRT"

Dim s As String
Dim v As Variant
Dim i As Long

Dim exApp As Excel.Application
Dim sheet As Excel.Worksheet

Set exApp = New Excel.Application
If Not exApp Is Nothing Then
exApp.Visible = True
If Not exApp Is Nothing Then
exApp.Workbooks.Add
Set sheet = exApp.ActiveSheet
If Not sheet Is Nothing Then
sheet.Cells(1, 2).Value = "X"
sheet.Cells(1, 3).Value = "Y"
sheet.Cells(1, 4).Value = "Z"
End If
End If
End If

Set swApp = GetObject(, "AlibreX.AutomationHook")
If Not swApp Is Nothing Then
Set doc = swApp.Root()

If Not doc Is Nothing Then
If doc.Type = swDocPART Then
Set part = sm
Set sm = doc.NewObjectCollector
If Not part Is Nothing And Not sm Is Nothing Then
If sm.SelectedObjects2(1) = swSelSKETCHES Then
Set feat = sm.SelectedObjects4(1)
Set sketch = feat.Root

If Not sketch Is Nothing Then
v = sketch.SketchNormal

For i = LBound(v) To UBound(v)
Set sp = v(i)
If Not sp Is Nothing And Not sheet Is Nothing And Not exApp Is Nothing Then
'sheet.Cells(2 + i, 1).Value = "Normal Vector " & i + 1
sheet.Cells(2 + i, 2).Value = Round(sp.x * 1000 / 25.4, DEC)
sheet.Cells(2 + i, 3).Value = Round(sp.y * 1000 / 25.4, DEC)
sheet.Cells(2 + i, 4).Value = Round(sp.z * 1000 / 25.4, DEC)
exApp.Columns.AutoFit
End If
Next i
End If
End If
End If
End If
End If
End If
End Sub
 

ashoks

New Member


Hi Harsimran,

I am Ashok at Alibre. I looked at the VB code you posted and thought I would share my observations:

- Going by the variable names you have used, it appears that you have made some incorrect corelations with the object they actually represent. The assumption on your part maybe due to your familiarity with another CAD product's automation API. For instance you have named the variable storing the AutomationHook object as "swApp". Actually, the AutomationHook is just the entry point to Alibre's API and it is really not equivalent to the "Application" object you seem to have in mind. Actually, the IADRoot that you get from AutomationHook is more like the "App" object. And, every IADSession object enumerated by the IADSessions collection in IADRoot is more like the "Document" object.

Also, it appears you are trying to access a skech using the the "Root" property of and IADPartFeature. This gives you the same old IADRoot mentioned above, not an IADSketch. To get the feature's sketch, you would need to first get the correct feature interface like IADExtrusionFeature and then look up its "Sketch" property.

- Going back to IADSession interface, your program can get hold of this interface for an already opened part (or assembly) by iterating over all the IADSession objects got from IADRoot and then using the "Name" property as a way to identify the IADSession of interest to you. Alternatively, you could have used the "OpenFile" method on IADRoot to open an existing Alibre part file on disk; this method will open the part and return you its IADSession interface. After confirming that the session is actually a "part" (by checking the "SessionType" property on IADSession), you can assign the IADSession to a variable declared as IADPartSession.

- You can then drill down the part to obtain the sketch object(IADSketch) you are interested in -- one way is via the "Sketches" property in IADPartSession.

- You can continue drilling down a IADSketch to obtain its sketch figures collection from IADSketch interface. A IADSketchFigure can be a IADSketchLine or IADSketchCircularArc etc depending on the "FigureType".

- You can then query the geometry properties of the IADSketchLine, IADSketchCircularArc etc. (like "Start", "End", "Center", "Radius" etc.). The points you will get is in the Sketch's 2D coordinate system. These need to be transformed appropriately to convert them to 3D World coordinates (of course, the SketchPlaneNorma is a 3D vector). Unfortunately, the api does not expose an method to convert a 2d sketch point to its equivalent 3d world coordinates though we have one for going other way around (see method MapFromWorldToSketch on IADSketch interface). This should be easy to provide in an upcoming service pack or so but until that time, you need to look for a workaround if you require the sketch geometry in 3D world coordinates.

- One possible work around for this is that you could navigate the topology of the solid model (basically faces and edges) and get hold of the edge geometry you are looking for (which will all be in 3D world coordinate space).

I trust you find my answer useful.

Regards,
-Ashok
 
Top