cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Mate two sub assemblies in the top assembly file with VB.

Highlighted
Level 7

Mate two sub assemblies in the top assembly file with VB.

Current scenario:

I have a subassembly(SAssem.asm) in the top assembly - (Inserted and constrained with CSYS using VB.NET)

Now I want to add another assembly and mate its CSYS with SAssem's CSYS. When I'm trying to do that using VB.NET, it is not able to find the SAssem's CSYS and mate with it.

Has anyone tried doing this before? or Let me know how to assemble two subassemblies with their CSYS using VB.

Any kind of help or tips are appreciated!

 

Thanks

1 REPLY 1

Re: Mate two sub assemblies in the top assembly file with VB.

I have attached the "VB API Users Guide" for PRO/Engineer WildFire 4.0

In this PDF there's an exaple on how to assembly components, see below.

My guess is that not much have changed for Creo.

 

Example: Assembling Components
The following example demonstrates how to assemble a component into an assembly, and how to constrain the
component by aligning datum planes. If the complete set of datum planes is not found, the function will show the
component constraint dialog to the user to allow them to adjust the placement.

Public Sub assembleByDatums(ByRef session As IpfcBaseSession, _
ByVal componentFileName As String, _
ByVal assemblyDatums() As String, _
ByVal componentDatums() As String)
Dim model As IpfcModel
Dim assembly As IpfcAssembly
Dim modelDesc As IpfcModelDescriptor
Dim componentModel As IpfcSolid
Dim asmcomp As IpfcComponentFeat
Dim constraints As IpfcComponentConstraints
Dim i As Integer
Dim asmItem As IpfcModelItem
Dim compItem As IpfcModelItem
Dim ids As Cintseq
Dim path As IpfcComponentPath
Dim asmSelect As IpfcSelection
Dim compSelect As IpfcSelection
Dim constraint As IpfcComponentConstraint
Dim errorCount As Integer
Try 
'======================================================================
'Get the current assembly and new component
'======================================================================
model = session.CurrentModel
If model Is Nothing Then
Throw New Exception("Model not present")
End If
If (Not model.Type = EpfcModelType.EpfcMDL_ASSEMBLY) Then
Throw New Exception("Model is not an assembly")
End If
assembly = CType(model, IpfcAssembly)
modelDesc = (New CCpfcModelDescriptor).CreateFromFileName(componentFileName)
componentModel = session.GetModelFromDescr(modelDesc)
If componentModel Is Nothing Then
componentModel = session.RetrieveModel(modelDesc)
End If
'======================================================================
'Package the component initially
'======================================================================
asmcomp = assembly.AssembleComponent(componentModel, 
nothing)
'======================================================================
'Prepare the constraints array
'======================================================================
errorCount = 0
constraints = New CpfcComponentConstraints
For i = 0 To 2
'==================================================================
'Find the assembly datum
'==================================================================
asmItem = assembly.GetItemByName(EpfcModelItemType.EpfcITEM_SURFACE, 
_assemblyDatums(i))
If asmItem Is Nothing Then 
errorCount = errorCount + 1
Continue For
End If
'==================================================================
'Find the component datum
'==================================================================
compItem = componentModel.GetItemByName(EpfcModelItemType.
EpfcITEM_SURFACE, 
_componentDatums(i))
If compItem Is Nothing Then 
errorCount = errorCount + 1
Continue For
End If
'==================================================================
'For the assembly reference, initialize a component path.
'This is necessary even if the reference geometry is in the assembly
'==================================================================
ids = New Cintseq
path = (New CMpfcAssembly).CreateComponentPath(assembly, 
ids)
'==================================================================
'Allocate the references
'==================================================================
asmSelect = (New CMpfcSelect).CreateModelItemSelection(asmItem, path)
compSelect = (New CMpfcSelect).CreateModelItemSelection(compItem, Nothing)
'==================================================================
'Allocate and fill the constraint
'==================================================================
constraint = (New CCpfcComponentConstraint).Create 
_(EpfcComponentConstraintType.EpfcASM_CONSTRAINT_ALIGN)
constraint.AssemblyReference = asmSelect
constraint.ComponentReference = compSelect
constraints.Insert(constraints.Count, constraint)
Next
'======================================================================
'Set the assembly component constraints and regenerate the assembly if
'atleast one constraint has been defined properly
'======================================================================
If errorCount < 2 Then
asmcomp.SetConstraints(constraints, Nothing)
assembly.Regenerate(Nothing)
session.GetModelWindow(assembly).Repaint()
End If
'======================================================================
'If any of the expect datums was not found, prompt the user to constrain
'the new component
'======================================================================
If errorCount > 0 Then
MsgBox("Unable to locate all required datum references." + 
_
"New component is packaged")
asmcomp.RedefineThroughUI()
End If
Catch ex As Exception
MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)
Exit Sub
End Try
End Sub