VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 6
sakamink
193 Views, 5 Replies

drawing

Stupid question,
but how do I define the commando "line"
And how do I draw a line?
5 REPLIES 5
Message 2 of 6
sakamink
in reply to: sakamink

I did found this:

Dim lineObj As AcadLine
Dim startPoint(0 To 2) As Double
Dim endPoint(0 To 2) As Double

' Define the start and end points for the line
startPoint(0) = 1#: startPoint(1) = 1#: startPoint(2) = 0#
endPoint(0) = 5#: endPoint(1) = 5#: endPoint(2) = 0#

' Create the line in model space
Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
ZoomAll


but do I need to retyp all this if I want to draw a new line on an other place??
Message 3 of 6
Anonymous
in reply to: sakamink

sakamink wrote:

> but do I need to retyp all this if I want to draw a new line on an other place??

No. Just create a function to do this with arguments for the
endpoints.

--
R.K. McSwain
http://rkmcswain.blogspot.com
Message 4 of 6
Anonymous
in reply to: sakamink

wrote in message news:5931666@discussion.autodesk.com...
Stupid question,

not a stupid question, just a question 🙂


but how do I define the commando "line"

that's really two questions
one: how to define a command
two: how to define a command that's already a built in autocad command

I'll just answer one, because I've never bothered to redefine an
autocommand, such as "Line"


I assume you mean how to define a command that you can enter at the autocad
command line to run a vba program?

If so, you have to define a lisp command to call a vba "sub" routine.
(unless you want to use the menu Tools|Macro|Macros and select a sub from
the list)
(defun C:NewCommand()
(FunctionToStartMacro)
)

once that lisp is loaded you have a new command "NewCommand" that will run
when entered at the command line

for the function to run the macro you have two choices depending on your
needs
vl-vbarun and vla-RunMacro

------------------------------------------------------------------------------
vl-vbarun
;;;vl-vbarun will allow you to pick on screen while a userform is hidden
;;; however, it will crash the macro if toolbar button is clicked
;;; AND IT WILL CANCEL PICKFIRST SELECTION SET

(FunctionToStartMacro(FullPathToDvbFile modname subname)
(setq macroname(strcat FullPathToDvbFile "!" modname "." subName))
(vl-vbarun macroname)
)
------------------------------------------------------------------------------

------------------------------------------------------------------------------
vla-runmacro
;;;vla-runmacro will prevent you from picking on screen while a userform is
hidden
;;;vla-runmacro is the only method that will allow you to use the
;;;PickFirstSelectionSet, and it is also the only method that will allow
;;;you to click a toolbar button while running a vba macro without crashing
the
;;;macro.

(FunctionToStartMacro(FullPathToDvbFile modname subname)
(setq macroname(strcat FullPathToDvbFile "!" modname "." subname))
(vla-runmacro (vlax-get-acad-object) macroname)
)
------------------------------------------------------------------------------


And how do I draw a line?

well, the easiest way is with a pencil and paper 🙂
but if you mean create a vba program to perform some action then hopefully
the above will give you a start

hth
mark
Message 5 of 6
sakamink
in reply to: sakamink

"I assume you mean how to define a command that you can enter at the autocad
command line to run a vba program?" not really

Actualy I have a userform with
Length: textbox(L)
With: textbox(W)

I want to draw a rectangle with dim (LxW)

I did found some code like this:

Private Sub CommandButton2_Click()

Dim lijn As AcadLine
Dim startpoint(0 To 2) As Double
Dim endpoint(0 To 2) As Double

startpoint(0) = x1: endpoint(0) = x2
startpoint(1) = y1: endpoint(1) = y2
startpoint(2) = 0: endpoint(2) = 0

Set lijn = ThisDrawing.ModelSpace.AddLine(startpoint, endpoint)
lijn.Update

' Drawing
Dim Le As Variant
Dim Wi As Variant
Le = L.Value
Wi = W.Value

now I dont know how to draw those 4 lines to get my rectangle, yes I want 4 lines, this is just a part of my programmation...

Someone knows how to do it,
I did try:
RetVal = Object.AddLine(startpoint(0,0), endpoint(L, 0, 0))
and
Call lijn(startpoint(0, 0,), endpoint(L, 0, 0))
but none of them works... Message was edited by: sakamink
Message 6 of 6
antoney
in reply to: sakamink

Actualy I have a userform with
Length: textbox(L)
With: textbox(W)
Private Sub CommandButton2_Click()

Dim line1 As AcadLine
Dim line2 As AcadLine
Dim line3 As AcadLine
Dim line4 As AcadLine

Dim insertionpnt(0 To 2) As Double
insertionpnt(0)=0: insertionpnt(1)=0: insertionpnt(2)=0

Dim point1(0 To 2) As Double
point1=insertionpoint
Dim point2(0 To 2) As Double
point2(0)=insertionpoint(0)+L
point2(1)=insertionpoint(1)
Dim point3(0 To 2) As Double
point3(0)=insertionpoint(0)+L
point3(1)=insertionpoint(0)+W
Dim point4(0 To 2) As Double
point3(0)=insertionpoint(0)
point3(1)=insertionpoint(0)+W

Set line1 = ThisDrawing.ModelSpace.AddLine(point1, point2)
line1.Update
Set line2= ThisDrawing.ModelSpace.AddLine(point2, point3)
line2.Update
Set line3 = ThisDrawing.ModelSpace.AddLine(point3, point4)
line3.Update
Set line4 = ThisDrawing.ModelSpace.AddLine(point4, point1)
line4.Update

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

Post to forums  

Autodesk Design & Make Report

”Boost