Message 1 of 17
Translating Points from Model Space to Assembly Space?

Not applicable
12-13-2004
11:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm knocking out a tool to copy componets in an Assembly.
I plan on making something more flexible than component patterns. (Lots of bells and whistles.)
I've set it up so the user select the component to copy and a Some component Edge (To define the vector to create the copies in.) I have a textbox for distance to translate along that vector.
So far my app can create the new component along the vector described (No control over distance yet.) , but it is in the component space vector.
Where I am stumbling is the the selected component edge start and end points are in the component defined Coordinate system. I need to convert that to Assembly space coordinates. (Not to mention calculating the new distance along that vector.) The goal is to create the copied component n distance from the original along the vector described.
I am having trouble locating the tools I need to do the job.
-- test code so far --
[pre]
Option Explicit
Private Sub CopyComponent(ByVal nCount As Integer)
Dim oDoc As AssemblyDocument
Dim oCompDef As AssemblyComponentDefinition
Dim oTG As TransientGeometry
Dim oSelectSet As SelectSet
Dim oMatrix As Matrix
Dim oEdge As Edge
Dim oOcc As ComponentOccurrence
Dim oOcc2 As ComponentOccurrence
Dim msg As String
Dim i As Integer
msg = "A Selected single component followed by a Selected single Edge (Vector)" & vbCrLf & _
"is required for this utility"
Set oDoc = ThisApplication.ActiveDocument
Set oSelectSet = oDoc.SelectSet
If oSelectSet.Count = 2 Then
If TypeOf oSelectSet(1) Is ComponentOccurrence Then
If TypeOf oSelectSet.Item(2) Is Edge Then
Set oOcc = oSelectSet(1)
Set oEdge = oSelectSet(2)
Set oTG = ThisApplication.TransientGeometry
Set oMatrix = oTG.CreateMatrix
Set oMatrix = oOcc.Transformation
Set oOcc2 = oDoc.ComponentDefinition.Occurrences. _
Add(oOcc.Definition.Document.fullfilename, oMatrix)
oMatrix.SetTranslation oEdge.StartVertex.Point.VectorTo(oEdge.StopVertex.Point), False
oOcc2.Transformation = oMatrix
Else
MsgBox msg
End If
Else
MsgBox msg
End If
Else
MsgBox msg
End If
Set oMatrix = Nothing
Set oOcc2 = Nothing
Set oOcc = Nothing
Set oEdge = Nothing
Set oSelectSet = Nothing
Set oTG = Nothing
Set oCompDef = Nothing
Set oDoc = Nothing
End Sub
[/pre]
I plan on making something more flexible than component patterns. (Lots of bells and whistles.)
I've set it up so the user select the component to copy and a Some component Edge (To define the vector to create the copies in.) I have a textbox for distance to translate along that vector.
So far my app can create the new component along the vector described (No control over distance yet.) , but it is in the component space vector.
Where I am stumbling is the the selected component edge start and end points are in the component defined Coordinate system. I need to convert that to Assembly space coordinates. (Not to mention calculating the new distance along that vector.) The goal is to create the copied component n distance from the original along the vector described.
I am having trouble locating the tools I need to do the job.
-- test code so far --
[pre]
Option Explicit
Private Sub CopyComponent(ByVal nCount As Integer)
Dim oDoc As AssemblyDocument
Dim oCompDef As AssemblyComponentDefinition
Dim oTG As TransientGeometry
Dim oSelectSet As SelectSet
Dim oMatrix As Matrix
Dim oEdge As Edge
Dim oOcc As ComponentOccurrence
Dim oOcc2 As ComponentOccurrence
Dim msg As String
Dim i As Integer
msg = "A Selected single component followed by a Selected single Edge (Vector)" & vbCrLf & _
"is required for this utility"
Set oDoc = ThisApplication.ActiveDocument
Set oSelectSet = oDoc.SelectSet
If oSelectSet.Count = 2 Then
If TypeOf oSelectSet(1) Is ComponentOccurrence Then
If TypeOf oSelectSet.Item(2) Is Edge Then
Set oOcc = oSelectSet(1)
Set oEdge = oSelectSet(2)
Set oTG = ThisApplication.TransientGeometry
Set oMatrix = oTG.CreateMatrix
Set oMatrix = oOcc.Transformation
Set oOcc2 = oDoc.ComponentDefinition.Occurrences. _
Add(oOcc.Definition.Document.fullfilename, oMatrix)
oMatrix.SetTranslation oEdge.StartVertex.Point.VectorTo(oEdge.StopVertex.Point), False
oOcc2.Transformation = oMatrix
Else
MsgBox msg
End If
Else
MsgBox msg
End If
Else
MsgBox msg
End If
Set oMatrix = Nothing
Set oOcc2 = Nothing
Set oOcc = Nothing
Set oEdge = Nothing
Set oSelectSet = Nothing
Set oTG = Nothing
Set oCompDef = Nothing
Set oDoc = Nothing
End Sub
[/pre]