To Change Reference Document in Derived part

To Change Reference Document in Derived part

RoyWickrama_RWEI
Advisor Advisor
615 Views
4 Replies
Message 1 of 5

To Change Reference Document in Derived part

RoyWickrama_RWEI
Advisor
Advisor

I was using the rule shown below some times ago.

When I use it today, it does not do any thing: the derived reference is not replaced with the document selected. I spent so much time without success.

 

Could someone help.

Thanks.

 

Public Sub Main()
	
Dim iL_NO As String = "0004DP"
Dim iL_Name As String = "Replace Derived Part Refeence"
Dim iL_FullName As String = iL_NO & ": " & iL_Name

Dim openDoc As Document
openDoc = ThisDoc.Document
'MessageBox.Show("openDoc: " & openDoc.FullFileName, iL_FullName)

If openDoc.DocumentType <> kPartDocumentObject Then 
	MessageBox.Show("This rule is for a part docuent only!", "File Type Mismatch!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
	Exit Sub
End If

Dim oRefFile As FileDescriptor
Dim oName_DerivedFile As Object     
Dim oFFN_DerivedParts_Array As New ArrayList
Dim oLFN_DerivedParts_Array As New ArrayList
Dim oCancel As String = "Cancel"

For Each oRefFile In openDoc.File.ReferencedFileDescriptors
oName_DerivedFile = oRefFile.FullFileName
oFFN_DerivedParts_Array.Add(oName_DerivedFile)

If oFFN_DerivedParts_Array.Count = 0 Then
MessageBox.Show("NO DERIVED PART(S) FOUND: Exit Sub!", iL_FullName)
Exit Sub
End If	

oPosition_LFN_oRefFile = InStrRev(oName_DerivedFile, "\", - 1) 
oLFN_oRefFile = Right(oName_DerivedFile, Len(oName_DerivedFile) - oPosition_LFN_oRefFile)
oLFN_DerivedParts_Array.Add(oLFN_oRefFile)
Next

'oLFN: Local File Name
oLFN_Selected_DerivedPart = InputListBox("Prompt", oLFN_DerivedParts_Array, oLFN_DerivedParts_Array(0), Title := iL_FullName, ListName := "LIST OF REFERENCE DOCS")
oIndex = oLFN_DerivedParts_Array.IndexOf(oLFN_Selected_DerivedPart)

oReferenceDoc_of_Selected_DerivedPart = oFFN_DerivedParts_Array(oIndex)
oReplace_DP(oReferenceDoc_of_Selected_DerivedPart)

iLogicVb.UpdateWhenDone = True

End Sub


Sub oReplace_DP(ByVal oReferenceDoc_of_Selected_DerivedPart As String)
	    Dim oThisActiveDoc As PartDocument = ThisApplication.ActiveEditDocument
	Dim oThisActiveDerivedDoc As PartDocument = ThisApplication.ActiveEditDocument						'Use where applicable
    Dim oThisActiveDocDef As PartComponentDefinition = oThisActiveDoc.ComponentDefinition
	
Dim oDoc As Document
oDoc = ThisDoc.Document
Dim oRefFile As FileDescriptor
Dim oOrigRefName As Object     
For Each oRefFile In oDoc.File.ReferencedFileDescriptors
'get the full file path to the original internal references
oOrigRefName = oRefFile.FullFileName
	If oRefFile.FullFileName = oReferenceDoc_of_Selected_DerivedPart Then
	'If oRefFile = oReferenceDoc_of_Selected_DerivedPart Then
		'present a File Selection dialog
		Dim oFileDlg As Inventor.FileDialog = Nothing
		InventorVb.Application.CreateFileDialog(oFileDlg)
		oFileDlg.InitialDirectory = oOrigRefName
		oFileDlg.CancelError = True
		On Error Resume Next
		oFileDlg.ShowOpen()
		If Err.Number <> 0 Then
		Return
		ElseIf oFileDlg.FileName <> "" Then
		selectedfile = oFileDlg.FileName
		End If
		MessageBox.Show("oRefFile: " & oRefFile.FullFileName _
		& vbLf & "selectedfile " & selectedfile, iL_FullName)

		'Replace the reference
		oRefFile.ReplaceReference(selectedfile)
	End If
Next
InventorVb.DocumentUpdate()
'oOrigRefName = “” 
iLogicVb.UpdateWhenDone = True

End Sub

 

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

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI,

 

Can you please provide non confidential data to test the behavior?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 5

RoyWickrama_RWEI
Advisor
Advisor

Thanks a lot. I will reply you back with samples.

Always best regards.

0 Likes
Message 4 of 5

RoyWickrama_RWEI
Advisor
Advisor

Thanks Chandra Shekar again.

I also need to get the derived part dialog box activated. Please see Figure 1.

 

Please see Figures 2 and 3 for my other issue.

Sample attached.

 

2019-11-28 23_15_58-Window.png

FIGURE-1

 

2019-11-28 22_59_24-Window.png

FIGURE-2

 

2019-11-28 23_11_28-Window.png

FIGURE-3

 

 

0 Likes
Message 5 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI,

 

Sorry for late reply,

 

Successfully replaced from one component(DOC0074.ipt) to another one(DOC0073.ipt). To demonstrate the same, a screencast video is prepared and uploaded to below link.

 

https://autode.sk/34NT0fW

 

To display derived part dialog, try below iLogic code.

    Dim oDoc As PartDocument
    oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As PartComponentDefinition
    oDef = oDoc.ComponentDefinition
    
    Dim oDerComp As DerivedPartComponent
    oDerComp = oDef.ReferenceComponents.DerivedPartComponents.Item(1)
    
   Call oDoc.SelectSet.Select(oDerComp)
    
    Call ThisApplication.CommandManager.ControlDefinitions.Item("PartEditDerivedPartCtxCmd").Execute

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes