Inventor 2018 crashes on iLogic rule

Inventor 2018 crashes on iLogic rule

joris.engelbertink
Enthusiast Enthusiast
882 Views
9 Replies
Message 1 of 10

Inventor 2018 crashes on iLogic rule

joris.engelbertink
Enthusiast
Enthusiast

Hi All,

 

So I have an iLogic rule to retrieve xyz model dimensions and put them into a custom iProperty. 

 

When I run the rule from the Part environment the rule works fine, inc the event trigger on any model parameter change. 

 

Now when I'm in the Assembly environment and Edit the Part from there, Inventor freezes and lets me no option than closing the program.

 

Any ideas on this issue? Thanks in advance!

 

Grt, Joris

 

0 Likes
Accepted solutions (1)
883 Views
9 Replies
Replies (9)
Message 2 of 10

JhoelForshav
Mentor
Mentor
Accepted solution

Are you by any chance referring to the document by ActiveDocument?

Ex. ThisApplication.ActiveDocument

 

Because when you are in edit mode like that it is still the Assembly that is the active document.

If you are, try chaning it to ThisDoc.Document instead. That will always get the document containing the rule.

 

If you share your code here it'll be easier to investigate what's wrong 🙂

0 Likes
Message 3 of 10

joris.engelbertink
Enthusiast
Enthusiast

Hi Jhoel ,

 

Thanks for your reply. Do you have a suggestion to improve my iLogic Rule? I'm quite new in this programming, so help is much appreciated 😉 

 

'convert to sheet metal part

ThisApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"

 

'add iProperties to Part

iLogicVb.RunExternalRule("Custom iProperties")

 

'get model dimensions

xdim = Measure.ExtentsLength

ydim = Measure.ExtentsWidth

zdim = Measure.ExtentsHeight

 

l = MaxOfMany(xdim, ydim, zdim)

t = MinOfMany(xdim,ydim,zdim)

b = xdim+ydim+zdim-l-t

 

'add model dimensions to Custom iProperties

iProperties.Value("Custom", "L") = Strings.FormatNumber(l, 0, , , 0)

iProperties.Value("Custom", "B") = Strings.FormatNumber(b, 0, , , 0)

iProperties.Value("Custom", "D") = Strings.FormatNumber(t, 0, , , 0)

 

'return to standard part

ThisApplication.ActiveDocument.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}"

0 Likes
Message 4 of 10

JhoelForshav
Mentor
Mentor

Hi @joris.engelbertink 

It's a pretty straight forward code so there's not much room for improvement 🙂

I don't know what your external rule "Custom iProperties" does, but if it doesn't do anything that requires the part to be a sheetmetal part there shouldn't be any reason to convert the part to sheet metal and then convert it back again

0 Likes
Message 5 of 10

joris.engelbertink
Enthusiast
Enthusiast

In this way I can extract the outer dimensions of a folded sheet metal part. 

 

When you look at the code, is it clear to you where it fails when editing a part within an assembly?  

 

Greetings, Joris

0 Likes
Message 6 of 10

JhoelForshav
Mentor
Mentor

There are a couple of things. The main thing however is that ThisApplication.ActiveDocument is still the assembly document even if you are editing the part from within the assembly. So you are trying to change the assembly to a sheet metal part on the first line of the code. But there are some other things as well.

 

If no one beats me to it I'll try to get back to you with some working code tomorrow and explain what I've changed and why.

 

Would you prefer that you have to enter edit mode on the part from within the assembly or would you rather have a code that asks you to simply click on the part you want to act upon with the code? Or maybe you'd like to just run the code and it will measure and set properties to all the parts in the assembly?

0 Likes
Message 7 of 10

WCrihfield
Mentor
Mentor

@joris.engelbertink 

  • So, this is a normal non-sheet metal part within an assembly, and you want to retrieve physical size measurements from that part and write them to the iProperties of that Part (not the assembly), correct?
  • Is this part already modeled as if it was bent, or is it flat?
    • If it is flat, you don't have to convert it to Sheet Metal to get its size.
    • If it is not flat, are trying to get the size of the material, after it is "flattened"?
      • If so, I'm not seeing where you are flattening the model out, before measuring it.
  • I agree with Joel, that you would need to define the part in a different way too.

Here is some code to get you a bit further along with what it sounds like you're trying to do.

This code doesn't convert the part to Sheet Metal and back, or Flatten the part...just measures it and writes those measurements to that parts iProperties, as you were trying to do, but in a different way.

But it should get you back on the right track.

 

 

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition

Dim oPOcc As ComponentOccurrence
Reselect :
oPOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Part.")
If oPOcc Is Nothing Then
	MsgBox("Nothing Selected. Exiting.")
	Return
End If
If oPOcc.DefinitionDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("Wrong document type selected. Please select a Part.", vbOK + vbExclamation, "WRONG DOCUMENT TYPE")
	GoTo Reselect
End If

Dim oPDoc As PartDocument = oPOcc.ReferencedDocumentDescriptor.ReferencedDocument
Dim oRB As Box = oPDoc.ComponentDefinition.RangeBox
Dim oXDim As Double = (oRB.MaxPoint.X - oRB.MinPoint.X)
Dim oYDim As Double = (oRB.MaxPoint.Y - oRB.MinPoint.Y)
Dim oZDim As Double = (oRB.MaxPoint.Z - oRB.MinPoint.Z)
Dim oL As Double = MaxOfMany(oXDim, oYDim, oZDim)
Dim oD As Double = MinOfMany(oXDim, oTDim, oZDim)
Dim oB As Double = (((oXDim + oYDim + oZDim) -oL) -oD)

Dim oCProps As PropertySet = oPDoc.PropertySets.Item("Inventor User Defined Properties")

'Insert code here to check if these iProperties exist or not, then create if not found.

oCProps.Item("L").Value = Strings.FormatNumber(oL,0,TriState.UseDefault,TriState.UseDefault,TriState.False)
oCProps.Item("B").Value = Strings.FormatNumber(oB,0,TriState.UseDefault,TriState.UseDefault,TriState.False)
oCProps.Item("D").Value = Strings.FormatNumber(oD,0,TriState.UseDefault,TriState.UseDefault,TriState.False)
oPDoc.Save

InventorVb.DocumentUpdate()

 

 

I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.

 

Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.

  • MessageBox, InputBox, and InputListBox Size & Format Options Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 10

joris.engelbertink
Enthusiast
Enthusiast
Hi, thanks for your reply.

my desire is to be able to run the run the rule when editing within an assembly and from the part environment itself.
no need for picking items or running my rule on complete assemblies. Thanks in advance!
0 Likes
Message 9 of 10

JhoelForshav
Mentor
Mentor

Hi @joris.engelbertink 

I still don't understand the reason to convert the part to sheet metal and back beacause it doesn't do any difference in this code. Maybe in your external rule the part has to be sheetmetal for it to run?

 

I tested it like this and you can run it both from edit in assembly and from within the part.

 

'convert To sheet metal part

ThisDoc.Document.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"

 

'add iProperties to Part

iLogicVb.RunExternalRule("Custom iProperties")

 

'get model dimensions

xdim = Measure.ExtentsLength

ydim = Measure.ExtentsWidth

zdim = Measure.ExtentsHeight

 

l = MaxOfMany(xdim, ydim, zdim)

t = MinOfMany(xdim,ydim,zdim)

b = xdim+ydim+zdim-l-t

 

'add model dimensions to Custom iProperties

iProperties.Value("Custom", "L") = Strings.FormatNumber(l, 0, , , 0)

iProperties.Value("Custom", "B") = Strings.FormatNumber(b, 0, , , 0)

iProperties.Value("Custom", "D") = Strings.FormatNumber(t, 0, , , 0)

 

'return to standard part

ThisDoc.Document.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}"

When testing i commented out the external rule call since i dont have your external rule.

If it still crashes now there must be a problem in the external rule so in order to further investigate I'd need you to attach that rule as well.

0 Likes
Message 10 of 10

WCrihfield
Mentor
Mentor

I was also going to suggest, within your code,  try swapping out "ThisApplication.ActiveDocument" with either of the following two options:

Dim oPDoc As PartDocument = ThisApplication.ActiveEditDocument
or
Dim oPDoc As PartDocument = ThisApplication.ActiveEditObject

Then use oPDoc in the rest of the code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes