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

Create part subassembly

Anonymous

Create part subassembly

Anonymous
Not applicable

I want to create a new part in the active subassembly? This is the code i have so far:

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveEditDocument
If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	
	Dim oNewPart As PartDocument
	
	'set to millimeter
		
    oNewPart = ThisApplication.Documents.Add(kPartDocumentObject,ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject)  , False)
	oNewPart.UnitsOfMeasure.LengthUnits =UnitsTypeEnum.kMillimeterLengthUnits 
	Dim oNewPartDef As PartComponentDefinition
    oNewPartDef = oNewPart.ComponentDefinition
	
	Dim oMartrix As Matrix
    oMatrix = ThisApplication.TransientGeometry.CreateMatrix()
	
	Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(0,0,0))

    'add the new part to the assembly
    Dim oNewOcc As ComponentOccurrence
	oNewOcc = oDoc.ComponentDefinition.Occurrences.AddByComponentDefinition(oNewPartDef,oMatrix)
	oNewOcc.Edit
End If

 

0 Likes
Reply
247 Views
1 Reply
Reply (1)

ianteneth
Advocate
Advocate

Hi! I think a little more information would help. I assume this code is not working? Where does the code fail? What else is needed in the code to achieve what you want?

0 Likes