Visual Basic Customization

Reply
Active Member
Posts: 6
Registered: ‎10-15-2002
Message 1 of 3 (56 Views)

Sendcommand

56 Views, 2 Replies
09-30-2002 03:23 PM
I am writing a program in AutoCAD 2000.

The program must change UCS a number of times referring to some blocks insert in 3D.
To change USC I use the following code

Public Function ChangeUcs (ObjHand As String) As Boolean
Dim Command As String

Command = "Ucs" & vbCr & "ob" & vbCr & "(HANDENT " & Chr(34) & ObjHand & Chr(34) & ") "
ThisDrawing.SendCommand Command

ChangeUcs = True

End Function

My problem is the following:

The program runs perfect when started from the VBA editor, but it will not run called direct from AutoCAD.

I seams, as the "sendcommand" is not executed before the program is ended.
I use the "sendcommand" I other variations without problems, so I assume it is the UCS operation that fails.

Can anyone give me a tip on how to run the code from AutoCAD?
*LHGO
Message 2 of 3 (56 Views)

Re: Sendcommand

09-30-2002 05:25 PM in reply to: Jbrauer
Sub Example_UCSIconAtOrigin()
   
' This example toggles the setting of UCSIconAtOrigin.

 

    Dim viewportObj As
AcadViewport
   
    ' Set the viewportObj
variable to the activeviewport
    Set viewportObj =
ThisDrawing.ActiveViewport
   
    ' Make
sure the UCS Icon is on, and a new UCS is defined.
    ' The
new UCS defines the origin for the icon. When the icon
    '
is not displayed at the origin, it is displayed at the
    '
lower-left corner of the display.
    Dim ucsObj As
AcadUCS
    Dim origin(0 To 2) As Double
   
Dim xAxisPoint(0 To 2) As Double
    Dim yAxisPoint(0 To 2) As
Double
    origin(0) = 2: origin(1) = 2: origin(2) =
0
    xAxisPoint(0) = 3: xAxisPoint(1) = 2: xAxisPoint(2) =
0
    yAxisPoint(0) = 2: yAxisPoint(1) = 3: yAxisPoint(2) =
0
    Set ucsObj =
ThisDrawing.UserCoordinateSystems.Add(origin, xAxisPoint, yAxisPoint,
"UCS1")
    ThisDrawing.ActiveUCS =
ucsObj
    viewportObj.UCSIconOn = True
   

    ' Display the current setting of
UCSIconAtOrigin
    MsgBox "UCSIconAtOrigin is: " &
IIf(viewportObj.UCSIconAtOrigin, "On", "Off"), , "UCSIconAtOrigin
Example"

 

    ' Toggle the setting of
UCSIconAtOrigin
    viewportObj.UCSIconAtOrigin = Not
(viewportObj.UCSIconAtOrigin)
   
    '
Reset the active viewport to see the change
   
ThisDrawing.ActiveViewport = viewportObj
   

    MsgBox "UCSIconAtOrigin is now: " &
IIf(viewportObj.UCSIconAtOrigin, "On", "Off"), , "UCSIconAtOrigin
Example"
   
End Sub


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
am writing a program in AutoCAD 2000.

The program must change UCS a number of times referring to some blocks
insert in 3D.
To change USC I use the following code

Public Function ChangeUcs (ObjHand As String) As Boolean
Dim Command As
String

Command = "Ucs" & vbCr & "ob" & vbCr & "(HANDENT " &
Chr(34) & ObjHand & Chr(34) & ") "
ThisDrawing.SendCommand
Command

ChangeUcs = True

End Function

My problem is the following:

The program runs perfect when started from the VBA editor, but it will not
run called direct from AutoCAD.

I seams, as the "sendcommand" is not executed before the program is ended.

I use the "sendcommand" I other variations without problems, so I assume
it is the UCS operation that fails.

Can anyone give me a tip on how to run the code from
AutoCAD?

Active Member
Posts: 6
Registered: ‎10-15-2002
Message 3 of 3 (56 Views)

Re:

10-01-2002 04:38 PM in reply to: Jbrauer
I have tried this way but in my case I have to calculate the x-Axis and y-axis from the Block properties.

I am not a mathematic genius, and my Knowles of vector mathematic is poor, so a friend of my have produced some program code that should do the calculation, BUT the algorithm is not reliable some time the UCS is turned upside down, and some time the x- and y-Axis is not the one AutoCAD find by using the USC OB command.

That’s why I try “sendcommand”, and as I write from the VBA editor I works nice, but not from AutoCAD.

If anyone can give an example of how to calculate the x- and y-Axis, from the data in the block properties that would be nice.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community