Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

API - ModelToViewTransform

339 views
Skip to first unread message

fatale...@yahoo.com

unread,
Dec 12, 2002, 7:47:18 AM12/12/02
to
I would like to automate the insertion of leadered notes
on a drawing at known position in the part model. The only
problem I am having is translating the points from the
part model to the drawing document.

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...

fatale...@yahoo.com

unread,
Dec 13, 2002, 4:22:14 PM12/13/02
to
Please, someone help me...
I am running out of hair to pull out.

Heikki Leivo

unread,
Dec 14, 2002, 3:45:42 AM12/14/02
to
Hello,

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...

Kevin Silbert

unread,
Dec 14, 2002, 8:02:00 AM12/14/02
to
I think the problem is that certain methods require you to put double
parenthesis around the variable you are passing. I know that
CreatePoint is one of those, and any CreateTransform should also, like

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

Kevin Silbert

unread,
Dec 15, 2002, 10:33:11 AM12/15/02
to
Oops- I guess I should have looked a bit closer first. The problem is
not in SafeArrays in this example- none of these methods need
SafeArrays. I'll see if I can look into it a bit later, but I'm sure
the answer is buried in the code I mentioned in the previous
posting...

Sorry for the false alarm,
-Kevin

ksil...@hotmail.com (Kevin Silbert) wrote in message news:<d4b68ca7.0212...@posting.google.com>...

Eric Zuercher

unread,
Dec 16, 2002, 10:02:28 AM12/16/02
to
I was never able to get the math utility to work so I wrote my own
routine for transforming from part to view. It's in a centerline
macro on Robert Hanson's website
http://www.cpuandsimplepdm.com/PublicSWAPICode.htm.

Eric

Kevin Silbert

unread,
Dec 16, 2002, 6:17:32 PM12/16/02
to
Try changing the DIM statement to this:

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

unread,
Dec 17, 2002, 3:31:06 PM12/17/02
to
Thank you both for your help. It took a little while, but I figured it
out.

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...

fatale...@yahoo.com

unread,
Dec 18, 2002, 7:20:12 AM12/18/02
to
Sorry guys! I meant to say thanks to all THREE of you. Thanks again...
0 new messages