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

Create part subassembly

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