Reply

Assemble Part - Match Coordinate Systems

[ Edited ]

 

Hello everyone,

I'm finding difficulties with the placement of a part in an assembly. Basically I want to assemble a part in an assembly with the 'match coordinate systems' method. Since I can't find this method as such in the API, it’s most probably a combination of three planar relationships of the planes of the two coordinate systems.

This is why I started to find out how to create a planar relationship between a plane of a coordinate system of the part, and of one of the assembly.

You need to make references of the planes (faces), but I can't get the reference of the plane in the assembly working. Pleas find my code below, and the example as attachment. Hopefully one of you can get me further.

Thanks in advance,

Wouter (Erwo)

______________________________________________

Public Sub PlacePart()

'On Error Resume Next

 

Dim objApp As SolidEdgeFramework.Application

Dim objDoc As SolidEdgeAssembly.AssemblyDocument

Dim objRelations3D As SolidEdgeAssembly.Relations3d

Dim objOccs As SolidEdgeAssembly.Occurrences

Dim objOcc As SolidEdgeAssembly.Occurrence

Dim objDocPar As SolidEdgePart.PartDocument

Dim objCoordSystemsPar As SolidEdgePart.CoordinateSystems

Dim objCoordSystemPar As SolidEdgePart.CoordinateSystem

Dim objCoordSystemsAsm As SolidEdgePart.CoordinateSystems

Dim objCoordSystemAsm As SolidEdgePart.CoordinateSystem

Dim objPlanePar1 As SolidEdgeGeometry.Face

Dim objPlanePar2 As SolidEdgeGeometry.Face

Dim objPlanePar3 As SolidEdgeGeometry.Face

Dim objPlaneAsm1 As SolidEdgeGeometry.Face

Dim objPlaneAsm2 As SolidEdgeGeometry.Face

Dim objPlaneAsm3 As SolidEdgeGeometry.Face

'Dim objRefPar1 As SolidEdgeFramework.Reference

'Dim objRefAsm1 As SolidEdgeFramework.Reference

Dim objRefPar1 As Object

Dim objRefAsm1 As Object

Dim ParArraj1A(1 To 2) As Double

Dim ParArraj1B(1 To 2) As Double

Dim ParArraj1AB(1 To 4) As Double

Dim ParArrajXYZ(1 To 6) As Double

Dim AsmArraj1A(1 To 2) As Double

Dim AsmArraj1B(1 To 2) As Double

Dim AsmArraj1AB(1 To 4) As Double

Dim AsmArrajXYZ(1 To 6) As Double

Dim strFNameASM As String

Dim strFNamePAR As String

Dim i As Integer

'Fill Variabeles

    strFNameASM = ThisWorkbook.Path & "\" & "TestASM.asm"

    strFNamePAR = ThisWorkbook.Path & "\" & "TestPAR.par"

 

'Get SE en open document

    Set objApp = GetObject(, "SolidEdge.Application")

    If Err Then

        Err.Clear

        Set objApp = CreateObject("SolidEdge.Application")

    End If

 

'Set

    Set objDoc = objApp.Documents.Open(strFNameASM)

    Set objOccs = objDoc.Occurrences

 

'Add Part by filename

    Call objOccs.AddByFilename(OccurrenceFileName:=strFNamePAR)

 

    'For i = 1 To objOccs.Count

    For Each objOcc In objOccs

        'Set objOcc = objOccs.Item(i)

 

        If objOcc.Name = "TestPAR.par:1" Then

            'Set ObjRelations

                Set objRelations3D = objOcc.Relations3d

                'Delete Ground Relation

                If objRelations3D.Count 0 Then

                    objOcc.Relations3d(1).Delete

                End If

 

                Set objRelations3D = objDoc.Relations3d

 

            'Add relationships to Coordinate System

                Set objDocPar = objOcc.OccurrenceDocument

                'Set CoordinateSystem (s)

                    Set objCoordSystemsPar = objDocPar.CoordinateSystems

                    Set objCoordSystemPar = objCoordSystemsPar.Item(1)

 

                    Set objCoordSystemsAsm = objDoc.CoordinateSystems

                    Set objCoordSystemAsm = objCoordSystemsAsm.Item(1)

 

                'Set Plane(s)

                    Set objPlanePar1 = objCoordSystemPar.Plane(seCoordSysXYPlane)

                    Set objPlanePar2 = objCoordSystemPar.Plane(seCoordSysYZPlane)

                    Set objPlanePar3 = objCoordSystemPar.Plane(seCoordSysZXPlane)

 

                    Set objPlaneAsm1 = objCoordSystemAsm.Plane(seCoordSysXYPlane)

                    Set objPlaneAsm2 = objCoordSystemAsm.Plane(seCoordSysYZPlane)

                    Set objPlaneAsm3 = objCoordSystemAsm.Plane(seCoordSysZXPlane)

 

                'Param part

                    objPlanePar1.GetRange ParArraj1A, ParArraj1B

                    For i = 1 To 2

                        ParArraj1AB(i) = (ParArraj1A(i) + ParArraj1B(i)) / 2

                    Next i

                    objPlanePar1.GetPointAtParam 1, ParArraj1AB, ParArrajXYZ

 

                'Param assembly

                    objPlaneAsm1.GetRange AsmArraj1A, AsmArraj1B

                    For i = 1 To 2

                        AsmArraj1AB(i) = (AsmArraj1A(i) + AsmArraj1B(i)) / 2

                    Next i

                    objPlaneAsm1.GetPointAtParam 1, AsmArraj1AB, AsmArrajXYZ

 

                'Make References

                    Set objRefPar1 = objDoc.CreateReference(objOcc, objPlanePar1)

                    'THIS IS WHERE IT GOES WRONG. A CAN'T SEEM TO GET IT WORKING

                    Set objRefAsm1 = objDoc.CreateReference2(objCoordSystemAsm, objPlaneAsm1)

 

                'Make Relationship (This should be done three time, for each of the three relationships)

                    objRelations3D.AddPlanar objRefPar1, objRefAsm1, False, ParArrajXYZ, AsmArrajXYZ

        End If

    Next

'Release objects

    Set objApp = Nothing

    Set objDoc = Nothing

 

    Set objRelations3D = Nothing

 

    Set objOccs = Nothing

    Set objOcc = Nothing

 

    Set objDocPar = Nothing

 

    Set objCoordSystemsPar = Nothing

    Set objCoordSystemPar = Nothing

 

    Set objCoordSystemsAsm = Nothing

    Set objCoordSystemAsm = Nothing

 

    Set objPlanePar1 = Nothing

    Set objPlanePar2 = Nothing

    Set objPlanePar3 = Nothing

 

    Set objPlaneAsm1 = Nothing

    Set objPlaneAsm2 = Nothing

    Set objPlaneAsm3 = Nothing

End Sub 

 

Posted by: Wouter Sloof
Post date: 10/18/2009 11:22:26 PM

2 REPLIES

RE: Assemble Part - Match Coordinate Systems

[ Edited ]

 

Hi Wouter,

 

This will work. I've done this in .NET, but it should be fine in Excel VBA. Edit the PartFile variable to be the path to your test part, open the test assy and try this:

 

Sub PlacePart()

 

Dim seApp As SolidEdgeFramework.Application

Dim seAssy As SolidEdgeAssembly.AssemblyDocument

Dim seOcc As SolidEdgeAssembly.Occurrence

Dim seAssyCOS As SolidEdgePart.CoordinateSystem

Dim sePart As SolidEdgePart.PartDocument

Dim sePartCOS As SolidEdgePart.CoordinateSystem

Dim seRels3D As SolidEdgeAssembly.Relations3d

Dim seRefOcc As SolidEdgeFramework.Reference

Dim PartXYPlane As SolidEdgeGeometry.Face

Dim PartYZPlane As SolidEdgeGeometry.Face

Dim PartZXPlane As SolidEdgeGeometry.Face

Dim AssyXYPlane As SolidEdgeGeometry.Face

Dim AssyYZPlane As SolidEdgeGeometry.Face

Dim AssyZXPlane As SolidEdgeGeometry.Face

Dim AXO, AYO, AZO, AXR, AYR, AZR As Double

Dim PXO, PYO, PZO, PXR, PYR, PZR As Double

Dim ConstrainingPoint(2) As Double

 

Dim PartFile As String

PartFile = "Enter file path here"

 

'get the solid edge application object

seApp = GetObject(, "SolidEdge.Application")

'get the current open assy

seAssy = seApp.ActiveDocument

'get the first coord system

seAssyCOS = seAssy.CoordinateSystems.Item(1)

'get coord info

seAssyCOS.GetOrientation(AXO, AYO, AZO, AXR, AYR, AZR)

 

'open the part document

sePart = seApp.Documents.Open(PartFile)

'get the first coord system

sePartCOS = sePart.CoordinateSystems.Item(1)

'get the co-ord details

sePartCOS.GetOrientation(PXO, PYO, PZO, PXR, PYR, PZR)

'close the part

sePart.Close(False)

 

'very simple less functional solution!

'seOcc = seAssy.Occurrences.AddWithTransform _

'(PartFile, AXO - PXO, AYO - PYO, AZO - PZO, AXR - PXR, AYR - PYR, AZR - PZR)

 

'place the part

seOcc = seAssy.Occurrences.AddByFilename(PartFile)

'delete the ground constraint

seOcc.Relations3d.Item(1).Delete()

 

'get the part coord planes

PartXYPlane = sePartCOS.Plane(seCoordSysXYPlane)

PartYZPlane = sePartCOS.Plane(seCoordSysYZPlane)

PartZXPlane = sePartCOS.Plane(seCoordSysZXPlane)

'get the assy coord planes

AssyXYPlane = seAssyCOS.Plane(seCoordSysXYPlane)

AssyYZPlane = seAssyCOS.Plane(seCoordSysYZPlane)

AssyZXPlane = seAssyCOS.Plane(seCoordSysZXPlane)

 

'get the assy relations

seRels3D = seAssy.Relations3d

'create a reference to the part xy plane

seRefOcc = seAssy.CreateReference(seOcc, PartXYPlane)

'add a planar relation between part xy plane ref and assy xy plane

'we're not bothered about the constraining point so we'll just send an array of zeros!

seRels3D.AddPlanar(seRefOcc, AssyXYPlane, False, ConstrainingPoint, ConstrainingPoint)

'create a reference to the part yz plane

seRefOcc = seAssy.CreateReference(seOcc, PartYZPlane)

'add a planar relation between part yz plane ref and assy yz plane

'we're not bothered about the constraining point so we'll just send an array of zeros!

seRels3D.AddPlanar(seRefOcc, AssyYZPlane, False, ConstrainingPoint, ConstrainingPoint)

'create a reference to the part zx plane

seRefOcc = seAssy.CreateReference(seOcc, PartZXPlane)

'add a planar relation between part zx plane ref and assy zx plane

'we're not bothered about the constraining point so we'll just send an array of zeros!

seRels3D.AddPlanar(seRefOcc, AssyZXPlane, False, ConstrainingPoint, ConstrainingPoint)

 

'tidy up

PartXYPlane = Nothing

PartYZPlane = Nothing

PartZXPlane = Nothing

AssyXYPlane = Nothing

AssyYZPlane = Nothing

AssyZXPlane = Nothing

seRefOcc = Nothing

seRels3D = Nothing

sePartCOS = Nothing

seAssyCOS = Nothing

seOcc = Nothing

seAssy = Nothing

seApp = Nothing

 

End Sub

You were pretty much there. You only need to make a reference to entities in an occurrence. It's OK to add the relations directly betwen the occ references and the assy entities. Also, the constraining points are not relevant in this case, because they are 'overidden' by the 3 plane alignments. They would only be applicable if you were going to leave an occurrence 'under-constrained' (for some reason).

 

Regards,

Dave

 

Posted by: Dave Rothan
Post date: 10/19/2009 10:40:25 PM

RE: Assemble Part - Match Coordinate Systems

[ Edited ]

 

Hello Dave,

You're the best! Thanks very much, it works great! I was close indeed but ready needed your help, thanks.

I've includes the working example as attachment, for everyone who wants to learn from it. It's VB6 code, written in MSExcel.

Best Regards,

Erwo

 

Posted by: Wouter Sloof
Post date: 10/20/2009 12:05:13 AM