In short, I am trying to determine the drawing view coordinates
for a known position on a part. I have written this little
macro to test the routine. As you can see, I simply hard-coded
the desired position from the part to simplify this post.
For this test, everything is in meters. The drawing has
a single view with a scale of 1:1.
Can anyone help me shed some light on what I am missing?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swDwg As DrawingDoc
Dim swView As View
Dim MathUtil As SldWorks.MathUtility
Dim MathModelPt As SldWorks.MathPoint
Dim MathViewPt As SldWorks.MathPoint
Dim MathTrans As SldWorks.MathTransform
Sub main()
Dim ptViewPos As Variant
Dim ptModel As Variant
Dim ptDwg As Variant
Dim pt1(3) As Double
Set swApp = GetObject(, "SldWorks.Application")
Set swDwg = swApp.ActiveDoc
'Get the first drawing view
Set swView = swDwg.GetFirstView
Set swView = swView.GetNextView
'Target Point on Model (.02, .03, .01)
'Target Point on Dwg (-.055, -.02)
pt1(0) = 0.02: pt1(1) = 0.03: pt1(2) = 0.01
ptModel = pt1
Set MathUtil = swApp.GetMathUtility
Set MathModelPt = MathUtil.CreatePoint(ptModel)
Set MathTrans = swView.ModelToViewTransform
Set MathViewPt = MathModelPt.MultiplyTransform(MathTrans)
ptDwg = MathViewPt.ArrayData()
swApp.SendMsgToUser "Hole Location" & vbCrLf & _
" Model: (0.02, 0.03, 0.01)" & vbCrLf & _
" Dwg Target: (-0.055, -0.02)" & vbCrLf & vbCrLf & _
" Calculated:" & " (" & ptDwg(0) & ", " & ptDwg(1) & ")"
End Sub
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks, in advance, for you help.
When all else fails, ask the experts...
I have used View.GetXForm and View.GetViewXForm succesfully. I have not
tried View.GetModelToVieTransform so I don't know what might be wrong. Quick
pick from my code:
Dim varXForm as Variant
Dim dblXForm(0 To 15) As Double
Dim objXForm As SldWorks.MathTransform
Dim i As Integer
varXForm = View.GetViewXForm
For i = 0 To UBound(varXForm)
dblXForm(i) = varXForm(i)
Next i
Set objXForm = objMathUtility.CreateTransform(dblXForm)
--> do something with objXForm
Hope this helps!
-h-
<fatale...@yahoo.com> wrote in message
news:40f78555.02121...@posting.google.com...
Set oTempVec = oMathUtil.CreatePoint((vTemp))
It has something to do with "passing safearrays" so check the APIhelp
under this name.
I did a LOT of headscratching on this in the past, and the program I
wrote (automatic hole chart) was in Solid Solutions magazine. The
full program (32 pages!) is in PDF form at
http://www.solidmag.com/Images/AutoHoleChartv1.pdf, or downloadable at
http://www.trimech.com/techsprt-free-utilities.htm (near the bottom-
look for the Automatic hole chart, not the interactive one). I
haven't looked at it in a while, and I hear that it may not work in
2003 (probably needs mods to work with multibody stuff). But I think
this answers your question.
-Kevin
fatale...@yahoo.com wrote in message news:<40f78555.02121...@posting.google.com>...
Sorry for the false alarm,
-Kevin
ksil...@hotmail.com (Kevin Silbert) wrote in message news:<d4b68ca7.0212...@posting.google.com>...
Eric
fatale...@yahoo.com wrote in message news:<40f78555.02121...@posting.google.com>...
Dim pt1(2) As Double
-rather than this:
Dim pt1(3) As Double
I get different results, but without your drawing, I can't verify that
it is correct. I remember noticing that this is very picky- to get 3
variables, dimension to (2) because (0) is the first...
Good luck!
-Kevin
fatale...@yahoo.com wrote in message news:<40f78555.02121...@posting.google.com>...
I had to go from the sketch coordinate to the model by using:
ModelToSketchTransform = swSketch.ModelToSketchXform
Set MathTransModel = MathUtil.CreateTransform(ModelToSketchTransform)
Set MathTransModel = MathTransModel.Inverse
Set MathPtModel = MathUtil.CreatePoint((PointCoords))
Set MathPtModel = MathPtModel.MultiplyTransform(MathTransModel)
Then, from the model coordinates to the drawing coordinates with:
Set MathTransDwg = swView.ModelToViewTransform
Set MathPtView = MathUtil.CreatePoint(PointCoords)
Set MathPtView = MathPtView.MultiplyTransform(MathTransDwg)
Then, using the swView.GetXform, I could get the view coordinates
based on the drawing origin.
Once again, thank you so very much...