iLogic Rule to be Ran Before Save

iLogic Rule to be Ran Before Save

Anonymous
Not applicable
613 Views
4 Replies
Message 1 of 5

iLogic Rule to be Ran Before Save

Anonymous
Not applicable

Hello Everyone,

 

I have skimmed through several posts about running iLogic rules for BOM structures and its naming convention, and I have managed to find a rule that I believe would work to change the part number to its display name in the model browser.

However, as I have a model already created, I'm struggling to pick apart other code that allows the rule to run for an assembly and its referenced files?

 

This is the code:

iProperties.Value("Project", "Part Number") = iProperties.Value("Occurrence", "Name")

Could I please have some help to run this for my current assembly?

0 Likes
614 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Can you be more specific / informational about what you are trying to do?

Do you have a main assembly open, and trying to change a ComponentOccurrence's "Part Number" property to that same Occurrence's (Occurrence.Name)?

Are you trying to change your main assembly "Part Number" property to one of the assembly's ComponentOccurrence names?

Are you trying to change a BOMRow Item Number, within a main assembly, to a ComponentOccurrence name instead of an Integer?

Have you already created a custom PropertySet named "Occurrence", within the main assembly, and added a property named "Name" to it, that you're wanting to use?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Anonymous
Not applicable

Yes sorry,

 

I'm trying to make the part number the same as that shown in the occurrence name in the iProperties options. 

I have an assembly all made, where I've used the frame generator tool, but the part number shows the 'standard-section-length'. Therefore I need to run the iLogic command in the assembly when using the generator, instead of manually changing the save file name or the part number.

 

I have not made a custom property as I thought that the occurrence section in the iProperties would already be built into 'code' ready to use. 

 

I also would change the assemblies part number to a bespoke format instead of its saved file name.

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Sorry for the delay.  Busy at work.  I created some quick code for you to try out.

See below code.

 

'Assuming the main assembly is open and active when you run this rule
'To change the main assembly's Part number use this line
iProperties.Value("Project", "Part Number") = "Whatever you want to put here"

'To change the Part Number of a ComponentOccurrence within the main assembly
'to its "Name" you would use code similar to the following

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument

'For a single Occurrence...Uncomment the next line (you may need to change which Occurrence)
'Dim oOcc As ComponentOccurrence = oADoc.ComponentDefinition.Occurrences.Item(1)

'Or...to loop through all Occurrences - Uncomment the next 3 lines
'For Each oOcc As ComponentOccurrence In oADoc.ComponentDefinition.Occurrences
'	iProperties.Value(oOcc.Name, "Project", "Part Number") = oOcc.Name
'Next

'Or...another route
For Each oDoc As Document In oADoc.AllReferencedDocuments
	'Open each referenced document, so you can access its iProperties
	ThisApplication.Documents.Open(oDoc.FullFileName, False)
	oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = oDoc.DisplayName
Next

 

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.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • 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
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

Anonymous
Not applicable

Hi there, incredibly sorry for replying sooner. The current situation has caused some margin of chaos at the office.

I haven't been able to try the code as of yet due to a shift in priority at work.

Once I'm back on the project I'll give it a bash.

0 Likes