VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ActiveX SetPlotWindow

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
449 Views, 3 Replies

ActiveX SetPlotWindow

I have posted a drawing to the customer files that illustrates a peculiar
problem I'm having. There is an embedded sub called
"getthedarnplotwindowright". It attempts to allow the user to specify a
plot window. Then it displays the preview. It also draws a line as a check
that the coordinates are correct. On certain drawings, the preview will not
calculate correctly, this is one. If you insert this drawing into a fresh
drawing, it will work correctly. My question is: What is it about this
drawing (and others) that is causing this malfunction?

thanks for your help,

-mjm
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

Hi Michael,

Check this out.

While using GetPoint method of AcadUtility object to obtain the points, you
must translate the coordinates to DCS (Display Coordinate System) before you
can use them in SetWindowToPlot method of Layout object.

GetPoint method (which allows you to pick a point on the screen) returns you
the picked point's 3D coordinates in WCS (i.e. World Coordinate System). So
you must translate the points from WCS to DCS before passing them to
SetWindowToPlot method. Please find below a sample code which highlights how
to achieve this.

For more details please refer the online help of AutoCAD VBA ActiveX and VBA
Developer's Guide->Chapter 8 -- Working in Three-Dimensional Space->
Converting Coordinates


Option Explicit
Sub f_plotWindow()
'paste this code in VBA of AutoCAD2000
'declare the required variables
Dim po_lay As AcadLayout
Dim p1 As Variant
Dim p2 As Variant

Set po_lay = ThisDrawing.ActiveLayout

'get two points
p1 = ThisDrawing.Utility.GetPoint(, "first point")
p2 = ThisDrawing.Utility.GetCorner(p1, "second point")

'translate the points which are in World UCS to Display coordinates
p1 = ThisDrawing.Utility.TranslateCoordinates(p1, acWorld, acDisplayDCS,
False)
p2 = ThisDrawing.Utility.TranslateCoordinates(p2, acWorld, acDisplayDCS,
False)

'change the variables from 3 element array to 2 element array
ReDim Preserve p1(0 To 1)
ReDim Preserve p2(0 To 1)

'reorder the points to lower left and upper right corner irrespective of
the way user selects the points
Call f_setCoord(p1, p2)
po_lay.SetWindowToPlot p1, p2
po_lay.PlotType = acWindow

ThisDrawing.Plot.DisplayPlotPreview acFullPreview
End Sub

Sub f_setCoord(p1 As Variant, p2 As Variant)
Dim pd_xMin As Double
Dim pd_yMax As Double

If p1(0) > p2(0) Then
pd_xMin = p2(0)
p2(0) = p1(0)
p1(0) = pd_xMin
End If
If p1(1) > p2(1) Then
pd_yMax = p2(1)
p2(1) = p1(1)
p1(1) = pd_yMax
End If
End Sub


Cheers,
Thilak

michael montagne wrote in message
news:ef06b16.-1@WebX.SaUCah8kaAW...
> I have posted a drawing to the customer files that illustrates a peculiar
> problem I'm having. There is an embedded sub called
> "getthedarnplotwindowright". It attempts to allow the user to specify a
> plot window. Then it displays the preview. It also draws a line as a
check
> that the coordinates are correct. On certain drawings, the preview will
not
> calculate correctly, this is one. If you insert this drawing into a fresh
> drawing, it will work correctly. My question is: What is it about this
> drawing (and others) that is causing this malfunction?
>
> thanks for your help,
>
> -mjm
>
Message 3 of 4
Anonymous
in reply to: Anonymous

Hi Thilak,
Thanks a million! I spent several hours trying to solve the same problem
and had finally ended up using code to create a view and plot it with the
PlotView method! Thanks for the tip! 🙂

- Adam

P.S.
I modified the code to work in R14. Hope it can help someone else. 🙂

'==========================================================
'Code by Thilak, modified for AutoCAD R14

Option Explicit
Sub f_plotWindow()
'paste this code in VBA of AutoCAD R14
'declare the required variables

Dim p1 As Variant
Dim p2 As Variant
Dim dblScale(0 To 1) As Double 'plot scale

'get two points
p1 = ThisDrawing.Utility.GetPoint(, "first point")
p2 = ThisDrawing.Utility.GetCorner(p1, "second point")

'translate the points which are in World UCS to Display coordinates
p1 = ThisDrawing.Utility.TranslateCoordinates(p1, acWorld, acDisplayDCS,
False)
p2 = ThisDrawing.Utility.TranslateCoordinates(p2, acWorld, acDisplayDCS,
False)

'change the variables from 3 element array to 2 element array
ReDim Preserve p1(0 To 1)
ReDim Preserve p2(0 To 1)

'reorder the points to lower left and upper right corner irrespective of
the way user selects the points
Call f_setCoord(p1, p2)

With ThisDrawing.Plot
.PlotScale = dblScale 'set scale to fit
.PlotWindow p1, p2 'set plot window
.PlotPreview acFullPreview 'show full preview
End With

End Sub

Sub f_setCoord(p1 As Variant, p2 As Variant)
Dim pd_xMin As Double
Dim pd_yMax As Double

If p1(0) > p2(0) Then
pd_xMin = p2(0)
p2(0) = p1(0)
p1(0) = pd_xMin
End If
If p1(1) > p2(1) Then
pd_yMax = p2(1)
p2(1) = p1(1)
p1(1) = pd_yMax
End If
End Sub
Message 4 of 4
Anonymous
in reply to: Anonymous

Thilak,
You have my admiration and respect. I'm still confused about why some
drawings worked and some did not but using the displayDCS instead of UCS
seems to work under all circumstances so I guess it doesn't matter so much.
Thank you very much.

-mjm

"Thilak" wrote in message
news:ef06b16.0@WebX.SaUCah8kaAW...
> Hi Michael,
>
> Check this out.
>
> While using GetPoint method of AcadUtility object to obtain the points,
you
> must translate the coordinates to DCS (Display Coordinate System) before
you
> can use them in SetWindowToPlot method of Layout object.
>
> GetPoint method (which allows you to pick a point on the screen) returns
you
> the picked point's 3D coordinates in WCS (i.e. World Coordinate System).
So
> you must translate the points from WCS to DCS before passing them to
> SetWindowToPlot method. Please find below a sample code which highlights
how
> to achieve this.
>
> For more details please refer the online help of AutoCAD VBA ActiveX and
VBA
> Developer's Guide->Chapter 8 -- Working in Three-Dimensional Space->
> Converting Coordinates
>
>
> Option Explicit
> Sub f_plotWindow()
> 'paste this code in VBA of AutoCAD2000
> 'declare the required variables
> Dim po_lay As AcadLayout
> Dim p1 As Variant
> Dim p2 As Variant
>
> Set po_lay = ThisDrawing.ActiveLayout
>
> 'get two points
> p1 = ThisDrawing.Utility.GetPoint(, "first point")
> p2 = ThisDrawing.Utility.GetCorner(p1, "second point")
>
> 'translate the points which are in World UCS to Display coordinates
> p1 = ThisDrawing.Utility.TranslateCoordinates(p1, acWorld,
acDisplayDCS,
> False)
> p2 = ThisDrawing.Utility.TranslateCoordinates(p2, acWorld,
acDisplayDCS,
> False)
>
> 'change the variables from 3 element array to 2 element array
> ReDim Preserve p1(0 To 1)
> ReDim Preserve p2(0 To 1)
>
> 'reorder the points to lower left and upper right corner irrespective
of
> the way user selects the points
> Call f_setCoord(p1, p2)
> po_lay.SetWindowToPlot p1, p2
> po_lay.PlotType = acWindow
>
> ThisDrawing.Plot.DisplayPlotPreview acFullPreview
> End Sub
>
> Sub f_setCoord(p1 As Variant, p2 As Variant)
> Dim pd_xMin As Double
> Dim pd_yMax As Double
>
> If p1(0) > p2(0) Then
> pd_xMin = p2(0)
> p2(0) = p1(0)
> p1(0) = pd_xMin
> End If
> If p1(1) > p2(1) Then
> pd_yMax = p2(1)
> p2(1) = p1(1)
> p1(1) = pd_yMax
> End If
> End Sub
>
>
> Cheers,
> Thilak
>
> michael montagne wrote in message
> news:ef06b16.-1@WebX.SaUCah8kaAW...
> > I have posted a drawing to the customer files that illustrates a
peculiar
> > problem I'm having. There is an embedded sub called
> > "getthedarnplotwindowright". It attempts to allow the user to specify a
> > plot window. Then it displays the preview. It also draws a line as a
> check
> > that the coordinates are correct. On certain drawings, the preview will
> not
> > calculate correctly, this is one. If you insert this drawing into a
fresh
> > drawing, it will work correctly. My question is: What is it about this
> > drawing (and others) that is causing this malfunction?
> >
> > thanks for your help,
> >
> > -mjm
> >
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost