iLogic: Fill in iProperty of parts and sub asssemblies, except "Purchased" Parts

iLogic: Fill in iProperty of parts and sub asssemblies, except "Purchased" Parts

Anonymous
Not applicable
1,771 Views
2 Replies
Message 1 of 3

iLogic: Fill in iProperty of parts and sub asssemblies, except "Purchased" Parts

Anonymous
Not applicable

Hello everyone,

 

I’m trying to create an iLogic routine that fills in the project number in the main assembly and all parts and sub asssemblies, except when a part or assembly is a “Purchased” part.

I have a rule now but it only adds the project number to the 1st layer of parts and subassemblies.

I have no clue how to have this rule fill in de project number in sub-sub assemblies and parts in sub-sub assemblies, etc. Until all levels are checked and filled in.

I hope you can really help me out. I checked several blogs on the Mod the Machine blog, but it seems that the code used there is nog working anymore in Inventor 2017.

 

 

The code I have is :

 

'Fill in project number

pProject = InputBox("Projectnummer", "Projectnummer")

 

' Get the active assembly.

Dim oAsmDoc As AssemblyDocument

oAsmDoc = ThisApplication.ActiveDocument

' Get the assembly component definition.

Dim oAsmCompDef As AssemblyComponentDefinition

oAsmCompDef = oAsmDoc.ComponentDefinition

 

' Iterate through all of the Part Occurrences

Dim oOccurrence As ComponentOccurrence

For Each oOccurrence In oAsmCompDef.Occurrences

' Set Reference to Occurrence Name

Dim oOccName As String

oOccName = oOccurrence.Name

 

If oOccurrence.Definition.BOMStructure = 51970 'Normal

iProperties.Value(oAsmDoc,"Project", "Project") = pProject

iProperties.Value(oOccName,"Project", "Project") = pProject

End If

 

If oOccurrence.Definition.BOMStructure = 51971 'Phantom

iProperties.Value(oAsmDoc,"Project", "Project") = pProject

iProperties.Value(oOccName,"Project", "Project") = pProject

End If

 

If oOccurrence.Definition.BOMStructure = 51972 'Reference

iProperties.Value(oAsmDoc,"Project", "Project") = pProject

iProperties.Value(oOccName,"Project", "Project") = pProject

End If

 

If oOccurrence.Definition.BOMStructure = 51974 'Inseparable

iProperties.Value(oAsmDoc,"Project", "Project") = pProject

iProperties.Value(oOccName,"Project", "Project") = pProject

End If

 

Next

 

Thanks a lot for taking time to read my question!

 

Best Regards,

 

Sjaak

 

0 Likes
Accepted solutions (1)
1,772 Views
2 Replies
Replies (2)
Message 2 of 3

MechMachineMan
Advisor
Advisor
Accepted solution

The blog you are looking for:

http://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html

 

The easiest working code:

 

pProject = InputBox("Projectnummer", "Projectnummer")

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

For Each oSubDoc in oAsmDoc.AllReferencedDocuments
If oSubDoc.IsModifiable = False Then: Continue For: End If

If oSubDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kPurchasedBOMStructure
oSubDoc.PropertySets("Design Tracking Properties")("Project").Value = pProject
End if
Next

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 3

Anonymous
Not applicable

Hello MechMachine,

 

Thanks a lot for your quick reply!  This is the exact information I was looking for.

 

I had to rebuild the code a little because I got an error in  these lines:

 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

 

And the project number wasn't added tot the main assembly itself so I added an extra line of code at the end as well. The complete code now looks like this and works perfect:

 

 

 

pProject = InputBox("Projectnummer", "Projectnummer")

' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
' Get the assembly component definition.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition


For Each oSubDoc in oAsmDoc.AllReferencedDocuments
If oSubDoc.IsModifiable = False Then: Continue For: End If

If oSubDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kPurchasedBOMStructure
oSubDoc.PropertySets("Design Tracking Properties")("Project").Value = pProject
End If

iProperties.Value(oAsmDoc,"Project", "Project") = pProject


Next