Create a working point inside an assembly

Create a working point inside an assembly

thomas_h_T36UT
Contributor Contributor
963 Views
5 Replies
Message 1 of 6

Create a working point inside an assembly

thomas_h_T36UT
Contributor
Contributor

Hello together,

 

I would like to greate six named working points inside an assembly, without any constrains. I need only the six named working points.

Does anyone has a solution?

0 Likes
Accepted solutions (2)
964 Views
5 Replies
Replies (5)
Message 2 of 6

nstevelmans
Advocate
Advocate
Accepted solution

Hi, this can be a start

 

 

 

 		
		Sub main
		Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
        Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

'-----------------------------------------------------------------------

        Create3Points(oCompDef, "Workpoint1", 5, 10, 20)
        Create3Points(oCompDef, "Workpoint2", 5, 10, 25)
		' add more points here
		
		
'-----------------------------------------------------------------------
		End Sub
		
		
		
	   Sub Create3Points(ByVal oCompdef As ComponentDefinition, ByVal name As String, x As Double, y As Double, z As Double)
        Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
        ' Create 3 workpoints to define the origin, x-direction and y-direction points
        Dim oWorkPoint1 As WorkPoint = oCompdef.WorkPoints.AddFixed(oTG.CreatePoint(x, y, z))
        oWorkPoint1.Name = name
    End Sub

 

If a response answers your question, please use  ACCEPT SOLUTION  to assist other users later.

Also be generous with Likes!  Thank you and enjoy!

 

Message 3 of 6

thomas_h_T36UT
Contributor
Contributor

Thanks for your quick responce. This is really helpfull for me.

0 Likes
Message 4 of 6

thomas_h_T36UT
Contributor
Contributor

Hello @nstevelmans ,

 

is it possible to add a working plane if nessasary?

 

0 Likes
Message 5 of 6

nstevelmans
Advocate
Advocate
Accepted solution

Hi, sorry for the late response, it was more complicated than I first thought.

De addworkplanes object is very limited in an assembly.

 

But you can try this.

 

 

  
  Sub main
  
  Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
        Dim oCompDef As AssemblyComponentDefinition = asmDoc.ComponentDefinition


        
        Dim oWorkPointList As New List(Of WorkPoint)

'-------------------------------------------------------------------------------------------------------

		Dim oWorkplane As Boolean = false

        Dim oWorkpoint1 As WorkPoint = Create3Points(oCompDef, "WP_1", -2.5, -1, 1)
        oWorkPointList.Add(oWorkpoint1)
        Dim oWorkpoint2 As WorkPoint = Create3Points(oCompDef, "WP_2", 2.5, -1, 1)
        oWorkPointList.Add(oWorkpoint2)
        Dim oWorkpoint3 As WorkPoint = Create3Points(oCompDef, "WP_3", 2.5, 1, 2)
        oWorkPointList.Add(oWorkpoint3)
        Dim oWorkpoint4 As WorkPoint = Create3Points(oCompDef, "WP_4", -2.5, -1, 3)
        oWorkPointList.Add(oWorkpoint4)
        Dim oWorkpoint5 As WorkPoint = Create3Points(oCompDef, "WP_5", 2.5, -1, 3)
        oWorkPointList.Add(oWorkpoint5)
        Dim oWorkpoint6 As WorkPoint = Create3Points(oCompDef, "WP_6", 2.5, 1, 4)
        oWorkPointList.Add(oWorkpoint6)
'------------------------------------------------------------------------------------------------------


        While oWorkPointList.Count > 2
            If oWorkplane = True Then
                Dim x1 As Double = oWorkPointList.Item(0).Point.X
                Dim y1 As Double = oWorkPointList.Item(0).Point.Y
                Dim z1 As Double = oWorkPointList.Item(0).Point.Z

                Dim x2 As Double = oWorkPointList.Item(1).Point.X
                Dim y2 As Double = oWorkPointList.Item(1).Point.Y
                Dim z2 As Double = oWorkPointList.Item(1).Point.Z

                Dim x3 As Double = oWorkPointList.Item(2).Point.X
                Dim y3 As Double = oWorkPointList.Item(2).Point.Y
                Dim z3 As Double = oWorkPointList.Item(2).Point.Z
                CreateWorkplane(oCompDef, x1, x2, x3, y1, y2, y3, z1, z2, z3)
            End If
            oWorkPointList.RemoveAt(0)
            oWorkPointList.RemoveAt(1)
            oWorkPointList.RemoveAt(0)
        End While
		
	End Sub
	
	
	 Private Function Create3Points(ByVal oCompdef As ComponentDefinition, ByVal name As String, x As Double, y As Double, z As Double) As WorkPoint
        Dim result As WorkPoint = Nothing
        Dim oWorkpoint As WorkPoint = Nothing
        Try
            Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
            ' Create 3 workpoints to define the origin, x-direction and y-direction points
            oWorkpoint = oCompdef.WorkPoints.AddFixed(oTG.CreatePoint(x, y, z))
            oWorkpoint.Name = name
            result = oWorkpoint

        Catch ex As Exception

        End Try
        Return result
    End Function
	
	
  Private Sub CreateWorkplane(oCompDef As AssemblyComponentDefinition, x1 As Double, x2 As Double, x3 As Double, y1 As Double, y2 As Double, y3 As Double, z1 As Double, z2 As Double, z3 As Double)
        Try
            Dim omidpoint As Point = ThisApplication.TransientGeometry.CreatePoint(x1, y1, z1)
            Dim oUnitVec1 As UnitVector = CreateUnitVector(x1, x2, y1, y2, z1, z2)
            Dim oUnitVec2 As UnitVector = CreateUnitVector(x1, x3, y1, y3, z1, z3)
            Dim oWorkplane As WorkPlane = oCompDef.WorkPlanes.AddFixed(omidpoint, oUnitVec1, oUnitVec2)
            oWorkplane.AutoResize = True
        Catch ex As Exception

        End Try
    End Sub
	
	
	 Private Function CreateUnitVector(workpoint1x As Double, workpoint2x As Double, workpoint1y As Double, workpoint2y As Double, workpoint1z As Double, workpoint2z As Double) As UnitVector
        Dim result As UnitVector = Nothing
        Dim oUnitVector As UnitVector = Nothing
        Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
        Try
            oUnitVector = oTG.CreateUnitVector(workpoint1x - workpoint2x, workpoint1y - workpoint2y, workpoint1z - workpoint2z)
            result = oUnitVector
        Catch ex As Exception
        End Try
        Return result
    End Function
0 Likes
Message 6 of 6

thomas_h_T36UT
Contributor
Contributor

I was on Holiday, so I have read your message right now. This is exactly what I was looking for, thank you very much again.

0 Likes