iLogic - how to pass custom property to parts and subassemblies

iLogic - how to pass custom property to parts and subassemblies

Anonymous
Not applicable
3,464 Views
7 Replies
Message 1 of 8

iLogic - how to pass custom property to parts and subassemblies

Anonymous
Not applicable

Hello All,

I'm new in iLogic functionally, but it gets me much satisfaction programming in it. Now I work on feature passing custom iproperties to parts and subassmeblies.

 

For example, I have parent assembly including parts and subassmblies. What I want to do is pass iproperty called "Drawing Number" of parent assembly to subparts, but not subassmeblies. Then if parent assembly has subassmebly, I would like to pass to parts in subassembly "Drawing Number" of subassembly.

I find out how to do this let's say in "one level assembly" (when assmembly doesn't have subassmeblies ), but I don't know how to go deeper. And It will be good if parts from Content Center stay unmodified.

Maybe some image tells what I mean:

Assembky.JPG

 

And code, which I made:

Sub Main Drawing_Number()
DrawNo=iProperties.Value("Project", "Part Number")

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oDef As AssemblyComponentDefinition
oDef = oDoc.ComponentDefinition

Dim oOcc As ComponentOccurrence
For Each oOcc in oDef.Occurrences
    If oOcc.SubOccurrences.Count = 0 Then
	
    	Dim docFile As Document
    	For Each docFile In oDoc.ReferencedDocuments
			If docFile.IsModifiable = False Then 
				'skip
    		Else If docFile.IsModifiable = True
    			Dim invCustomPropertySet As PropertySet= docFile.PropertySets.Item("Inventor User Defined Properties")
        		Try
            	Dim invVolumeProperty As Inventor.Property = invCustomPropertySet.Item("Drawing Number")
            	invVolumeProperty.Value = DrawNo
        		Catch
            		Call invCustomPropertySet.Add(DrawNo, "Drawing Number")
        		End Try
			End If
    	Next
    Else
        Call CheckSubAssem(oOcc)
    End If
Next

'	MassOfVisible=Round(MassOfVisible,2)
'	iProperties.Value("Custom", oDef.RepresentationsManager.ActiveDesignViewRepresentation.Name)=MassOfVisible

End Sub

Public Sub CheckSubAssem(ByVal oCompOcc As ComponentOccurrence)
    
    Dim oSubCompOcc As ComponentOccurrence

	'MessageBox.Show(DrawNo, "Title")

    
    For Each oSubCompOcc In oCompOcc.SubOccurrences
        If oSubCompOcc.SubOccurrences.Count = 0 Then
		MessageBox.Show(oCompOcc.Name, "Title")
		DrawNo1=oCompOcc.Name
    	Dim docFile As Document
		Dim oDoc As AssemblyDocument
		oDoc = ThisApplication.ActiveDocument
		
    	For Each docFile In oDoc.ReferencedDocuments
			If docFile.IsModifiable = False Then 
				'skip
    		Else If docFile.IsModifiable = True
    			Dim invCustomPropertySet As PropertySet= docFile.PropertySets.Item("Inventor User Defined Properties")
        		Try
            	Dim invVolumeProperty As Inventor.Property = invCustomPropertySet.Item("Drawing Number")
            	invVolumeProperty.Value = DrawNo1
        		Catch
            		Call invCustomPropertySet.Add(DrawNo1, "Drawing Number")
        		End Try
			End If
    	Next
		
        Else
            Call CheckSubAssem(oSubCompOcc)
        End If
    Next
End Sub

 

0 Likes
Accepted solutions (1)
3,465 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Following:

Dim a As Application
Set a = ThisApplication

Dim b As AssemblyDocument
Set b = a.ActiveDocument

Call loopDwgNr(b)
End Sub


Public Sub loopDwgNr(Ass As AssemblyDocument)



Dim ComPoccs As ComponentOccurrences
Set ComPoccs = Ass.ComponentDefinition.Occurrences

Dim compocc As ComponentOccurrence
Dim ChildDoc As Document
Set ChildDoc = Nothing
For Each compocc In ComPoccs
Set ChildDoc = compocc.Definition.Document
Dim DrawingNr As String
DrawingNr = Ass.PropertySets.Item(3).Item("Part Number").Value
'MsgBox Ass.PropertySets.Item(3).Item("Project").Value
'MsgBox Ass.PropertySets.Item(3).Item("Part Number").Value
If ChildDoc.DocumentType = kPartDocumentObject Then

On Error Resume Next
ChildDoc.PropertySets.Item(4).Add "DrawingNr", "DrawNo"
If Error Then
Err.Clear
End If
ChildDoc.PropertySets.Item(4).Item("DrawNo").Value = DrawingNr


End If

If ChildDoc.DocumentType = kAssemblyDocumentObject Then

Call loopDwgNr(ChildDoc)

End If

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 8

MechMachineMan
Advisor
Advisor
Accepted solution

Recursion is a beautiful thing!

 

Sub Main Drawing_Number()
    DrawNo=iProperties.Value("Project", "Part Number")

    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument

    Call SetChildrenDrawingNumber(oDoc, DrawNo)   
End Sub

Sub SetChildrenDrawingNumber(oDoc as Document, DrawNo AS String)
If oDoc.ReferencedDocuments.Count > 0 Then
For Each oSubDoc in oDoc.ReferencedDocuments
If oSubDoc.DocumentType = DocumentTypeEnum.kAsssemblyDocumentObject
oThisDwgNumber = oSubDoc.PropertySets("Inventor User Defined Properties")("Drawing Number").Value
Call SetChildrenDrawingNumber(oSubDoc, oThisDwgNumber)
Else
Try
oSubDoc.PropertySets("Inventor User Defined Properties")("Drawing Number").Value = DrawNo
Catch
oSubDoc.PropertySets("Inventor User Defined Properties").Add(DrawNo, "Drawing Number)
End try
End if
Next
End if
End Sub

 


--------------------------------------
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
0 Likes
Message 4 of 8

Anonymous
Not applicable

Many thanks MechMachineMan,

After few modifications of code it works very well. I had to adapt it for my daily work:)

0 Likes
Message 5 of 8

Anonymous
Not applicable

One more issue...

I find out how to recognize Content Center part 

 

If docFile.IsModifiable = True/False Then

and it works in my code when part is "really" from CC. But what if, for example I took CC part and saved it as new part to change description or material. 

This component has his own "Drawing Number" and I don't want to rewrite it.

How to recognize this component?

0 Likes
Message 6 of 8

MechMachineMan
Advisor
Advisor

Do you often rewrite old Drawing Numbers in parts, or should the first one added be the one it stays as for life in that part? Or do you need to override the values for a copied design?

 

I don't think there is any "well known" way that says if the part was generated from content center. I think I had seen somewhere that they have a HIDDEN property set, but don't quote me on it.


--------------------------------------
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
0 Likes
Message 7 of 8

Anonymous
Not applicable

Error on Line 13 : 'kAsssemblyDocumentObject' is not a member of 'Inventor.DocumentTypeEnum'.

 

Please advise how to fix this error

 

 

0 Likes
Message 8 of 8

P_Korgaonkar
Advocate
Advocate

I am getting the same error on line 13

 

Regards

parag

0 Likes