Possible to copy/paste derived ipt filename into the parent ipt file ilogic code?

Possible to copy/paste derived ipt filename into the parent ipt file ilogic code?

kwilson_design
Collaborator Collaborator
1,133 Views
6 Replies
Message 1 of 7

Possible to copy/paste derived ipt filename into the parent ipt file ilogic code?

kwilson_design
Collaborator
Collaborator

Hey everyone,

 

Is it possible to copy a derived ipt filename and paste it into some illogic code? I have some ilogic code where we import the part number iproperty from a derived part and paste it into the Stock Number iproperty field of the parent ipt file. 

 

Below is the ilogic code I would like to add the derived ipt filename information where you see the "PSBxxxxxxx.ipt" text...

 

iProperties.Value("Project", "Stock Number") = iProperties.Value("PSBxxxxxxx.ipt","Project","Part Number")
	iProperties.Value("Custom", "Raw Material Description") = iProperties.Value("PSBxxxxxxx.ipt","Project","Description")

 

Regards,
Kenny
If this post solved your issue please mark "Accept as Solution". It helps everyone...really!
0 Likes
Accepted solutions (2)
1,134 Views
6 Replies
Replies (6)
Message 2 of 7

Andrii_Humeniuk
Advisor
Advisor

Hi @kwilson_design . This is a code sample of how to get properties from a DrivePart and write it to the main part.

Sub main
	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
	If oDef.ReferenceComponents.DerivedPartComponents Is Nothing Then Exit Sub
	If oDef.ReferenceComponents.DerivedPartComponents.Count <> 0 Then
		Dim oDrivePart As DerivedPartComponent = oDef.ReferenceComponents.DerivedPartComponents.Item(1)
		Dim oDriveDoc As PartDocument = oDrivePart.ReferencedDocumentDescriptor.ReferencedDocument
		Dim sPartNumb As String = oDriveDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		Dim sDescription As String = oDriveDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
		oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value = sPartNumb
		Try
			oDoc.PropertySets.Item("Inventor User Defined Properties").Item("Raw Material Description").Value = sDescription
		Catch
			oDoc.PropertySets.Item("Inventor User Defined Properties").Add(sDescription, "Raw Material Description")
		End Try
	End If
End Sub

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 7

kwilson_design
Collaborator
Collaborator

Hi @Andrii_Humeniuk, thanks for taking a look into this. When I replaced my original code with you code, it doesn't seem to copy the derived filename into the stock number.  I don't get any ilogic errors but nothing is populated in the stock number iproperty field. Our workaround has ben to manually copy the derived ipt filename and paste it directly into the placeholder "PSBxxxxxx.ipt" section of the code.

source field empty.jpg

raw mtl forum code.jpg

 

Regards,
Kenny
If this post solved your issue please mark "Accept as Solution". It helps everyone...really!
0 Likes
Message 4 of 7

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Sorry, I made a mistake, here is the code that copies the part number. Notice line 10 in the old and new code.

Sub main
	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
	If oDef.ReferenceComponents.DerivedPartComponents Is Nothing Then Exit Sub
	If oDef.ReferenceComponents.DerivedPartComponents.Count <> 0 Then
		Dim oDrivePart As DerivedPartComponent = oDef.ReferenceComponents.DerivedPartComponents.Item(1)
		Dim oDriveDoc As PartDocument = oDrivePart.ReferencedDocumentDescriptor.ReferencedDocument
		Dim sPartNumb As String = oDriveDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		Dim sDescription As String = oDriveDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
		oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value = sPartNumb
		Try
			oDoc.PropertySets.Item("Inventor User Defined Properties").Item("Raw Material Description").Value = sDescription
		Catch
			oDoc.PropertySets.Item("Inventor User Defined Properties").Add(sDescription, "Raw Material Description")
		End Try
	End If
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 5 of 7

kwilson_design
Collaborator
Collaborator

Perfect! That did the trick and works like a charm. Thanks for the help and have a great day!

Regards,
Kenny
If this post solved your issue please mark "Accept as Solution". It helps everyone...really!
Message 6 of 7

kwilson_design
Collaborator
Collaborator

@Andrii_Humeniuk I am running into a snag as I'm updating all of our department's files to use this code. If I open a single drawing (IDW) of one of the parts that use the code, everything works fine. However if I try and open multiple drawing files at once and try to save them all at once, I'm getting this error message for the ipt files and can't bulk save the drawing files. I did some digging on here and don't understand why it's throwing this code when you have the file document specified as a part file. Any ideas?

 

Error message:

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

More info: 

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Regards,
Kenny
If this post solved your issue please mark "Accept as Solution". It helps everyone...really!
0 Likes
Message 7 of 7

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @kwilson_design . This is due to the fact that earlier the code received the document from the active file, if you replace the 2nd line with ThisDoc.Document, then the rule will receive the document from the file in which the rule is located.

Sub main
	Dim oDoc As PartDocument = ThisDoc.Document
	Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
	If oDef.ReferenceComponents.DerivedPartComponents Is Nothing Then Exit Sub
	If oDef.ReferenceComponents.DerivedPartComponents.Count <> 0 Then
		Dim oDrivePart As DerivedPartComponent = oDef.ReferenceComponents.DerivedPartComponents.Item(1)
		Dim oDriveDoc As PartDocument = oDrivePart.ReferencedDocumentDescriptor.ReferencedDocument
		Dim sPartNumb As String = oDriveDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		Dim sDescription As String = oDriveDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
		oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value = sPartNumb
		Try
			oDoc.PropertySets.Item("Inventor User Defined Properties").Item("Raw Material Description").Value = sDescription
		Catch
			oDoc.PropertySets.Item("Inventor User Defined Properties").Add(sDescription, "Raw Material Description")
		End Try
	End If
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes