Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
RoyWickrama_RWEI
490 Views, 5 Replies

Create derived part: to bring the one or more part document into the current doc

Could some one help me on the following - Thanks.

 

2020-03-13 23_14_32-Window.png

 

 

 

DRoam
in reply to: RoyWickrama_RWEI

The following code will derive in multiple parts, whose filenames are specified under the "Specify parts to derived in" section. You could instead use a loop of InputBoxes to specify part filenames, or some other method -- I wasn't sure what to do because you didn't provide any details about how you want to specify the parts to be derived in.

 

Dim ruleTitle As String = "Derive Multiple"

' Get current part document (the "recipient" part)
Dim partDoc As PartDocument = ThisDoc.Document

' Set reference to Derived Part Components manager for recipient part
Dim derPartComps As DerivedPartComponents = partDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents

' Specify parts to derived in (the "source" parts)
Dim sourcePartPaths As New List(Of String)
sourcePartPaths.Add("C:\...\PartToDeriveIn.ipt") ' <-- Change to path of the part you want to derive in.
sourcePartPaths.Add("...") ' <-- Repeat for each desired source part.

If sourcePartPaths.Count > 0 Then
	' Start transaction
	Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(partDoc, ruleTitle)
	
	' Derive in each specified part
	Dim failedParts As New List(Of String)

	For Each sourcePartPath As String In sourcePartPaths
		If IO.File.Exists(sourcePartPath) Then
			Dim derivedPartDef As DerivedPartUniformScaleDef
			
			Try
				' Create definition for derived part.
				derivedPartDef = derPartComps.CreateUniformScaleDef(sourcePartPath)
			Catch ex As Exception
				failedParts.Add("- '" & sourcePartPath & "': Error creating derive definition: '" & ex.Message & "'")
				Continue For
			End Try
			
			Try
				' Set up the Derive.
				'derivedPartDef.IncludeAll
				'derivedPartDef.IncludeAllSolids = True
			Catch ex As Exception
				failedParts.Add("- '" & sourcePartPath & "': Error setting up derive: '" & ex.Message & "'")
				Continue For
			End Try
			
			Try
				' Create Derive feature.
				derPartComps.Add(derivedPartDef)
			Catch ex As Exception
				failedParts.Add("- '" & sourcePartPath & "': Error creating derive feature: '" & ex.Message & "'")
			End Try
		Else
			failedParts.Add("- '" & sourcePartPath & "': File does not exist")
		End If
	Next
	
	If failedParts.Count = sourcePartPaths.Count Then
		trans.Abort
	Else
		trans.End
	End If
	
	If failedParts.Count > 0 Then
		MessageBox.Show("The following parts could not be Derived:" & vbCr & vbCr & String.Join(vbCr, failedParts), ruleTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
	End If
Else
	MessageBox.Show("Must provide at least one Part to derive in.", ruleTitle, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

 

RoyWickrama_RWEI
in reply to: DRoam

Thanks a lot for the reply.

This is the kind of rule I could never see in the forum.

It works great and is a great great help.

 

It brings all the entities in to the current document.

I do not like to bother you.

 

But, could you help me to get the following Derived Style dialog box. Thanks a lot.

 

2020-03-17 20_13_17-Window.png

DRoam
in reply to: RoyWickrama_RWEI

Hi @RoyWickrama_RWEI, take a look at this page in the API documentation: DerivedPartDefinition Object. It covers how to set all of those configurations by applying them to the "derivedPartDef" object.

RoyWickrama_RWEI
in reply to: DRoam

Thanks for the guide line.

I will be able to get this around.

Will let you know the progress.

 

RoyWickrama_RWEI
in reply to: DRoam

Thanks DRoam.

I keep tailoring the rule to my needs. (rule attached here to)

 

Case - 1:

Currently, I have the following issue: i.e. the derived does not appear in the browser unless I close and reopen.

I appreciate receiving some help.

 

2020-03-21 22_20_08-Window.png

Case-2:

Still I could not figure out how to invoke the Derive Part Derive Style dialog box.

2020-03-21 22_30_19-Window.png