Changing TARGET Variable by code

Changing TARGET Variable by code

Anonymous
Not applicable
2,926 Views
4 Replies
Message 1 of 5

Changing TARGET Variable by code

Anonymous
Not applicable
We are using a plotroutine in VBA wich works fine. However, sometimes the plotwindows gets moved around and it has taken me quite some time to figure out what is causing the problem. I found out it has something to do with the TARGET Variable. When making a good plot the TARGET coordinates are 0,0,0 but when the plot gets moved is had coordinates like 179935,69574,0. The problem is that this variable is a READ only.

Does anyone know how I could change the TARGET variable in VBA code so I can fix this in the routine? There has to be some way because the drawing started out with 0,0,0 coordinates, so something changed these values. Any help would be greatly appreciated.
0 Likes
2,927 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

ThisDrawing.SetVariable sysVarName, sysVarData

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
We
are using a plotroutine in VBA wich works fine. However, sometimes the
plotwindows gets moved around and it has taken me quite some time to figure
out what is causing the problem. I found out it has something to do with the
TARGET Variable. When making a good plot the TARGET coordinates are 0,0,0 but
when the plot gets moved is had coordinates like 179935,69574,0. The problem
is that this variable is a READ only. Does anyone know how I could change the
TARGET variable in VBA code so I can fix this in the routine? There has to be
some way because the drawing started out with 0,0,0 coordinates, so something
changed these values. Any help would be greatly
appreciated.
0 Likes
Message 3 of 5

Anonymous
Not applicable
I've tried the following code but it fails. It generates an error, my first thought is that this is because the target var is a read only variable.
Does anyone know how the target variable is set by Autocad in the first place?

Dim arrayData3D(0 To 2) As Double
sysVarName = "TARGET"
arrayData3D(0) = 1#: arrayData3D(1) = 1#: arrayData3D(2) = 0
sysVarData = arrayData3D

ThisDrawing.SetVariable sysVarName, sysVarData
0 Likes
Message 4 of 5

Anonymous
Not applicable
Finally I managed to get som e results regarding my TARGET problem. It seems that by changing values using DVIEW you change the target coordinates. So I managed to set thet TARGET to 0,0,0 by hand, now I'll figure out how to put this into usefull code.
0 Likes
Message 5 of 5

Anonymous
Not applicable
jeromeb wrote:
> Finally I managed to get som e results regarding my TARGET problem. It
> seems that by changing values using DVIEW you change the target
> coordinates. So I managed to set thet TARGET to 0,0,0 by hand, now I'll
> figure out how to put this into usefull code.

Hello jerome

We have encountered something like your problem I think.

I have made the following VBA Sub to Reset the Center+Target coordinates
for the current viewport in Modelspace of the active drawing in AutoCAD:

This method may help you also our give you some ideas.


Public Sub ResetMSViewPort()
'Reset Current View/Camera for Current Model Space ViewPort
Dim oACADDraw As AcadDocument
Dim oCurViewP As AcadViewport
Dim dCenter(1) As Double
Dim dTarget(2) As Double
'Get Current AutoCAD Drawing Document Object
Set oACADDraw = ThisDrawing
If Not (oACADDraw Is Nothing) Then
'Check for Model Space Active
If (oACADDraw.ActiveSpace = acModelSpace) Then
'Get the Active ViewPort Object
Set oCurViewP = oACADDraw.ActiveViewport
If Not (oCurViewP Is Nothing) Then
'Set ViewPort Center Coordinates to (X,Y)=(0,0)
dCenter(0) = 0#
dCenter(1) = 0#
'Set the ViewPort Center Coordinates
oCurViewP.Center = dCenter
'Set ViewPort Target Coordinates to (X,Y,Z)=(0,0,0)
dTarget(0) = 0#
dTarget(1) = 0#
dTarget(2) = 0#
'Set the ViewPort Target Coordinates
oCurViewP.Target = dTarget
'Set the Active ViewPort to the Modified ViewPort Object
oACADDraw.ActiveViewport = oCurViewP
'Release ViewPort Object
Set oCurViewP = Nothing
End If
End If
'Release Document Object
Set oACADDraw = Nothing
End If
Exit Sub
End Sub


Regards
Jens Bejer Pedersen
0 Likes