Copying Derived Parent's iProprties without using ActiveDocument.DocumentType

Copying Derived Parent's iProprties without using ActiveDocument.DocumentType

Jacob.PawelskiUVPDL
Contributor Contributor
101 Views
1 Reply
Message 1 of 2

Copying Derived Parent's iProprties without using ActiveDocument.DocumentType

Jacob.PawelskiUVPDL
Contributor
Contributor

Currently using the following rule to copy iProperties from Parent to Child for Derived Parts. (Copied from another forum post years ago).
 

If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
	MessageBox.Show("Make a Part Document the active document,Exiting", "iLogic") 
Else

	Dim oDerDoc As PartDocument
	oDerDoc = ThisApplication.ActiveDocument

	'Look for Derived part components
	If oDerDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count < 1 Then
		MessageBox.Show("No Derived Part Components in this part", "iLogic")   

	ElseIf oDerDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count > 1 Then
		MessageBox.Show("More than one Derived Part Components in this part,Exiting!", "iLogic") 
	Else
		
		' Set a reference to the part component definition
		Dim oDerCompDef As PartComponentDefinition
		oDerCompDef = oDerDoc.ComponentDefinition
		
		'Get a reference to derived part components in this part
		Dim oDerComps As DerivedPartComponents
		oDerComps = oDerCompDef.ReferenceComponents.DerivedPartComponents
		
		'Get a reference to derived part component
		Dim oDerComp As DerivedPartComponent
		oDerComp = oDerComps(1)'1st component
		'MessageBox.Show(oDerComp.Name, "iLogic")
		
		' Get the Reference document.
		Dim oRefDoc As Document
		oRefDoc = oDerComp.ReferencedDocumentDescriptor.ReferencedDocument
		
        'Creates the iProperty in the derived part and assigns the iProperty value of the refDoc
		iProperties.Value("Summary", "Title") = iProperties.Value(oRefDoc.DisplayName, "Summary", "Title")
		iProperties.Value("Project", "Description") = iProperties.Value(oRefDoc.DisplayName, "Project", "Description")
		iProperties.Value("Project", "Part Number") = ThisDoc.FileName(False)
		'MessageBox.Show("iProperty Copied from Parent to Child", "Success")
	End If
End If


While this works fine when working on the individual ipt, it runs into problems when located in an assembly and either trying to regen all rules at the assembly or editing the part in place and running the rule.
Our current workflow is to open each individual ipt and run the rule to update the iProperties. This is not a good workflow. 

I don't know enough about iLogic to rewrite the code in a way that works. Any Suggestions?

0 Likes
102 Views
1 Reply
Reply (1)
Message 2 of 2

gerrardhickson
Collaborator
Collaborator

Hi @Jacob.PawelskiUVPDL,

 

"Give a man a fish and you'll feed him for a day, Teach a man to fish and you'll feed him for a lifetime".

The best advice I can offer is to take whatever code you have and make sure you understand what its doing line by line.

Once you understand it, start trying to change it by making small changes and see if they do what you expect.

If you run into trouble, come to the forums to ask specific questions - e.g. "I tried <this> but my code did <that>".

Buuuuttttt.... If you prefer not to learn, you could try this code instead:

 

If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("Make an Assembly Document the active document.", "iLogic") 
Else

	Dim oDerDoc As AssemblyDocument
	oDerDoc = ThisApplication.ActiveDocument
	
	Dim X1 As Integer

	For Each oPart As PartDocument In oDerDoc.AllReferencedDocuments
		'Look for Derived part components
		If oPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count < 1 Then
			'MessageBox.Show("No Derived Part Components in this part", "iLogic")   
	
		ElseIf oPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count > 1 Then
			'MessageBox.Show("More than one Derived Part Components in this part,Exiting!", "iLogic") 
		Else
			
			' Set a reference to the part component definition
			Dim oDerCompDef As PartComponentDefinition
			oDerCompDef = oPart.ComponentDefinition
			
			'Get a reference to derived part components in this part
			Dim oDerComps As DerivedPartComponents
			oDerComps = oDerCompDef.ReferenceComponents.DerivedPartComponents
			
			'Get a reference to derived part component
			Dim oDerComp As DerivedPartComponent
			oDerComp = oDerComps(1)'1st component
			'MessageBox.Show(oDerComp.Name, "iLogic")
			
			' Get the Reference document.
			Dim oRefDoc As Document
			oRefDoc = oDerComp.ReferencedDocumentDescriptor.ReferencedDocument
			
	        'Creates the iProperty in the derived part and assigns the iProperty value of the refDoc
			iProperties.Value(oPart.DisplayName, "Summary", "Title") = iProperties.Value(oRefDoc.DisplayName, "Summary", "Title")
			iProperties.Value(oPart.DisplayName, "Project", "Description") = iProperties.Value(oRefDoc.DisplayName, "Project", "Description")
			iProperties.Value(oPart.DisplayName, "Project", "Part Number") = oPart.DisplayName.Replace(".ipt","")
			'MessageBox.Show("iProperty Copied from Parent to Child", "Success")
			X1+=1
		End If
	Next oPart
	MessageBox.Show("iProperties copied from Parent to Child for " & X1 & " documents.", "Copy Complete")
End If

 

I hope that helps.

0 Likes