Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need VBA coding help(Faceperimeter, laser cutting length)

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
463 Views, 1 Reply

Need VBA coding help(Faceperimeter, laser cutting length)

Have been using the FacePerimeter found here on Inventor forum, but is doesnt make custom property with total length.

Then i found another macro that can do this for me, but it is in inches.

 

Can this macro easily be converted to mm or cm? all help appreciated, this will save me alot of time 🙂

 

Heres the code im using:

 

Dim LaserInchs As Double


Sub Laser()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSMDef As SheetMetalComponentDefinition
Set oSMDef = oDoc.ComponentDefinition

Dim oFace As Face
Set oFace = oSMDef.FlatPattern.TopFace

Dim Laser As Double
TotalLength = 0

Dim oEdge As Edge
For Each oEdge In oFace.Edges
Dim oEvaluator As CurveEvaluator
Set oEvaluator = oEdge.Evaluator

Dim minparam As Double
Dim maxparam As Double
Call oEvaluator.GetParamExtents(minparam, maxparam)

Dim length As Double
Call oEvaluator.GetLengthAtParam(minparam, maxparam, length)

Laser = Laser + length

Next

Dim LaserInchs As Double
LaserInchs = oDoc.UnitsOfMeasure.ConvertUnits(Laser, kDatabaseLengthUnits, kInchLengthUnits)
'area = Round(oFace, 4)
Dim oCustomPropSet As PropertySet

Set oCustomPropSet = oDoc.PropertySets.Item("User Defined Properties")

' Check to see if the property already exists.
On Error Resume Next
Dim oCustomProp As Property
Set oCustomProp = oCustomPropSet.Item("Laser")
If Err Then
' It doesn't exist, so create it.
Set oCustomProp = oCustomPropSet.Add(LaserInchs, "Laser")
End If

' Set the value.
oCustomProp.Value = Format(LaserInchs, "0.0000")

MsgBox "Laser: " & Format(LaserInchs, "0.0000") & " in"
End Sub

 

 

 

 

1 REPLY 1
Message 2 of 2
ekinsb
in reply to: Anonymous

Internally, Inventor always uses centimeters for length.  The calcuation portion of the program is getting the result in centimeters and then converting that result to inches using the ConvertUnits method, which is stores in the LaserInchs variable.

 

There are a couple of approaches you can take to get the results you're looking for.  First, if you want centimeters you can use the value in the Laser variable and not worry about any conversion.  Second, you can use kMillimeterLengthUnits or kCentimeterLengthUnits in the ConvertUnits call to specify millimeters or centimeters.  Finally, you can use kDefaultDisplayLengthUnits, which will use whatever units the user has currently specified to be their default units in the Document Settings dialog.

 

LaserLength = oDoc.UnitsOfMeasure.ConvertUnits(Laser, kDatabaseLengthUnits, kDefaultDisplayLengthUnits)


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report