Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

iLogic Rule Problems in Assembly

Anonymous

iLogic Rule Problems in Assembly

Anonymous
Not applicable

I have a part with an iLogic rule which derives a sketch and scales it from a user parameter. The rule then sets the sketch as a profile and then extrudes it, again by a length specified by a user parameter. Finally, I then apply a circular pattern to the extruded feature.

Within the part file, this rule runs flawlessly and I get the results I want, however. When I add the part to an assembly and run the rule. I get the following error;

ErrorError

I need to have this rule run in the assembly but I can't seem to get this to work without getting this error.

If anyone has any idea on how to get this to work from an assembly, i would be extremely grateful as this error is really slowing my work down.

 

Here is the iLogic rule too;

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument 

' Create a derived definition for the molded part.
Dim oDerivedPartDef As DerivedPartUniformScaleDef
oDerivedPartDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(ThisDoc.Path + "\" & "innerStrands90.ipt")

' Set the scale to use.
oDerivedPartDef.ScaleFactor = scale
    
' Create the derived part.
oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPartDef) 

' Extrude sketch
' Set sketch to profile
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches
Dim oSketch As PlanarSketch
oSketch = oSketches.Item("Core")
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid

' Extrude
Dim oExtrudeDef As ExtrudeDefinition
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation)
oDistance = length / 10
oDirection = kPositiveExtentDirection
oJoinOrCut = kJoinOperation
Dim oExtrude As ExtrudeFeature
oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, oDistance, oDirection, oJoinOrCut)
oExtrude.Name = "extrudedCore"

' Circular pattern
Dim objCol As ObjectCollection
objCol = ThisApplication.TransientObjects.CreateObjectCollection
objCol.Add(oCompDef.Features("extrudedCore"))
oDeg = 360 * 0.0174532925
oCompDef.Features.CircularPatternFeatures.Add(objCol, oCompDef.WorkAxes.Item("Z Axis"), False, 4, oDeg, True)

 Thank you.

0 Likes
Reply
Accepted solutions (2)
606 Views
3 Replies
Replies (3)

Sergio.D.Suárez
Mentor
Mentor

Hi, Try this code in the ilogic rule.

 

Dim oPartDoc As PartDocument
oPartDoc = ThisDoc.Document


' Create a derived definition for the molded part.
Dim oDerivedPartDef As DerivedPartUniformScaleDef
oDerivedPartDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(ThisDoc.Path + "\" & "innerStrands90.ipt")

' Set the scale to use.
oDerivedPartDef.ScaleFactor = scale
    
' Create the derived part.
oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPartDef) 

' Extrude sketch
' Set sketch to profile
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches
Dim oSketch As PlanarSketch
oSketch = oSketches.Item("Core")
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid

' Extrude
Dim oExtrudeDef As ExtrudeDefinition
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation)
oDistance = length / 10
oDirection = kPositiveExtentDirection
oJoinOrCut = kJoinOperation
Dim oExtrude As ExtrudeFeature
oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, oDistance, oDirection, oJoinOrCut)
oExtrude.Name = "extrudedCore"

' Circular pattern
Dim objCol As ObjectCollection
objCol = ThisApplication.TransientObjects.CreateObjectCollection
objCol.Add(oCompDef.Features("extrudedCore"))
oDeg = 360 * 0.0174532925
oCompDef.Features.CircularPatternFeatures.Add(objCol, oCompDef.WorkAxes.Item("Z Axis"), False, 4, oDeg, True)

 

In your rule there is a line that says
  "oPartDoc = ThisApplication.ActiveDocument"
that refers to the active document, and when you open your assembly your active document is the assembly, that's why it will give you the error, since your document must be the part, in the example change this line by
"oPartDoc = ThisDoc.Document"

 

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

Anonymous
Not applicable
Accepted solution

Thank you for that Yuvilo! 

 

That seemed to be the fix I was looking for, however I am now getting another error...

2019-03-07_10-54-08.png

and I believe it could be line highlighted in green below;

Dim oPartDoc As PartDocument
oPartDoc = ThisDoc.Document

' Create a derived definition for the molded part.
Dim oDerivedPartDef As DerivedPartUniformScaleDef
oDerivedPartDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(ThisDoc.Path + "\" & "innerStrands90.ipt")

' Set the scale to use.
oDerivedPartDef.ScaleFactor = 2
    
' Create the derived part.
oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPartDef) 

' Extrude sketch
' Set sketch to profile
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches
Dim oSketch As PlanarSketch
oSketch = oSketches.Item("Core")
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid

' Extrude
Dim oExtrudeDef As ExtrudeDefinition
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation)
oDistance = length / 10
oDirection = kPositiveExtentDirection
oJoinOrCut = kJoinOperation
Dim oExtrude As ExtrudeFeature
oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, oDistance, oDirection, oJoinOrCut)
oExtrude.Name = "extrudedCore"

' Circular pattern
Dim objCol As ObjectCollection
objCol = ThisApplication.TransientObjects.CreateObjectCollection
objCol.Add(oCompDef.Features("extrudedCore"))
oDeg = 360 * 0.0174532925
oCompDef.Features.CircularPatternFeatures.Add(objCol, oCompDef.WorkAxes.Item("Z Axis"), False, 4, oDeg, True)

 I'm new to using iLogic to drive parts in Inventor so any help is massively appreciated. 

 

Thank you.

0 Likes

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

You're right, sorry I had not seen that line, you also have to replace it with this

oSketches =  ThisDoc.Document.ComponentDefinition.Sketches

 or

 

oSketches = oPartDoc.ComponentDefinition.Sketches

I hope your problem has been solved greetings!


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