Using ilogic rules in a template file to run a macro works on part but not asse

Using ilogic rules in a template file to run a macro works on part but not asse

Anonymous
Not applicable
577 Views
6 Replies
Message 1 of 7

Using ilogic rules in a template file to run a macro works on part but not asse

Anonymous
Not applicable

Basically what I have is a part template that runs a few different macros using ilogic. The part template works great on it's own but when I use said template to create a new part within an assembly the ilogic rules error out during the assembly save. I'm almost positive that it has to do with the part needing a flat pattern to run the other rules, so I guess my question would be...Is there a macro or something I can use that would allow for a new component to create a flat pattern on the initial save in the assembly environment? The other thing it may be is one of the macros has the following code in it, maybe it cannot be ran from the assembly environment?

 

Dim oDoc As PartDocument

Set oDoc = ThisApplication.ActiveDocument 

 

Thanks in advance 

0 Likes
578 Views
6 Replies
Replies (6)
Message 2 of 7

bradeneuropeArthur
Mentor
Mentor
Is this instead!

Dim oDoc As PartDocument

Set oDoc = ThisApplication.ActiveEditDocument 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 7

Anonymous
Not applicable

Thank you! That got the code past that error now it is erroring out on the following line of code?

 

Dim oFace As Face

For Each oFace In oFlatPattern.Body.Faces

 

Would this be where I need to be able to create the flatpattern from the assembly level?

 

Thanks!

0 Likes
Message 4 of 7

Anonymous
Not applicable

Basically this is what I am trying to do

Environment  - Assembly

Create new part using  template

Template has the following macros being used by ilogic on save.

Create flat pattern and save dxf

run macro to populate total linear cut length to custom iproperty

Copy surface area  to custom iproperty

Like I said it works great when creating a stand alone part, but when creating a new part based off of other assembly components it errors out on the Total Length macro where I have shown above in the code snippet.

 

Thanks again!

 

0 Likes
Message 5 of 7

Sergio.D.Suárez
Mentor
Mentor

The code segment you just showed refers to the active document

Dim oDoc As PartDocument

 

Set oDoc = ThisApplication.ActiveDocument

 

If you are in the assembly, the active document is the assembly, not the part document, for this reason you will return the error.
The simplest solution that occurs to me is that you work purely with ilogic, since you can define the specific document in the rules as


Dim oDoc As PartDocument = ThisDoc.Document


This entry for example could be in your part template and if you execute it from the assembly it will reference the part document even if the active document is the assembly.
The other path that I suppose could be viable in VBA would be to open the part from assembly, and establish this file as an active document before executing the rules.
If you have some simplified files that do not contain confidential information, share them to see if we can help you. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 6 of 7

Anonymous
Not applicable

Sergio,

I have attached my current template that currently works great on its own. I am new to the ilogic and programming so I am a little confused on where I would add your segment so it would run in an assembly? Just a rule that runs on save of the part template? Basically what happens, while in the assembly environment is I create a new part based off of other items already in the assembly and when I am finished and hit return or finish edit and then click save the file saves but it errors out on my total length code which I believe is due to the fact that it has not created the flatpattern yet along with my total length macro being incorrect, which I have fixed at this point by changing ThisApplication.ActiveDocument to ThisApplication.ActiveEditDocument. I am trying to avoid right clicking and opening the part but if we have to do that I totally understand. It also happens again any time I move a part created with the template into another assembly and save it or if the part is adaptive, basically when anything changes in the part the error issues again.

Thanks!

0 Likes
Message 7 of 7

Anonymous
Not applicable
Below is the Total Length Macro that errors out do I need to move this into ilogic? If so is it a simple copy and paste? Sub GetTotalLength() Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument Dim oFace As Face 'Set oFace = oDoc.SelectSet(1) Set oFace = GetTopFaceOfFlat Dim TotalLength 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) TotalLength = TotalLength + length Next Dim TotalLengthInchs As Double TotalLengthInchs = oDoc.UnitsOfMeasure.ConvertUnits(TotalLength, kDatabaseLengthUnits, kInchLengthUnits) Dim oCustomPropSet As PropertySet Set oCustomPropSet = oDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}") On Error Resume Next Dim oCustomProp As Property Set oCustomProp = oCustomPropSet.Item("TotalLength") If oCustomProp Is Nothing Then Set oCustomProp = oCustomPropSet.Add(Format(TotalLengthInchs, "0.000"), "TotalLength") Else oCustomProp.Value = Format(TotalLengthInchs, "0.000") End If End Sub Function GetTopFaceOfFlat() As Face Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument Dim oDef As SheetMetalComponentDefinition Set oDef = oDoc.ComponentDefinition 'Assumes that the flat has been created Dim oFlatPattern As FlatPattern Set oFlatPattern = oDef.FlatPattern Dim oFace As Face For Each oFace In oFlatPattern.Body.Faces ' Only interested in planar faces If oFace.SurfaceType = kPlaneSurface Then Dim oPlane As Plane Set oPlane = oFace.Geometry Dim oZAxis As UnitVector Set oZAxis = ThisApplication.TransientGeometry.CreateUnitVector(0, 0, 1) ' Only interested in faces that have z-direction normal If oPlane.Normal.IsParallelTo(oZAxis) Then ' Look for the face with Z = 0 If oPlane.RootPoint.Z <= 0.0000001 Then Set GetTopFaceOfFlat = oFace Exit For End If End If End If Next End Function
0 Likes