TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CECE_CAD on May 28, 2008, 04:26:33 PM
-
I would like to have a command create the drawing attached.. I have no idea how to even start this.. I would like the user to be prompted to enter the “Round” width, then the “Square” width, and then the depth. I would like to learn how to create this routine as it’s over my head. If someone can help assist me I’m willing to dig in.
-
And start you will.
First you need the user to supply:
point1 and point 2, then a height.
(setq pt1 (getpoint "\nSelect first point: "))
(setq pt2 (getpoint pt1 "\nSelect width: "))
etc.
Then ask the user to supply an angle or length of top line.
Take information, throw in some trig and the square part (name escapes me) is ready.
For the triangle you already have point1 and 2. To get the midpoint, use polar.
-
I don't have time this evening to help you with the code but I can tell you the first step is creating some pseudo code.
This is a description of what you want to accomplish in the order that logically works through the task.
In your case you started out with some descriptions already.
User input: get the Square width
User input: get the Round width (diameter)
User input: get the length or run of the transition
[Note: these were all distances so use the getdist function and you
may want to use the initget to filter out incorrect choices]
User input: get the location to draw the object
Error check all user input, stop if incorrect
Verify and / or create the DUCT layer
Draw the object using COMMAND or entmakex
User input: get rotation of the new object
Does that describe the task?
<edit: added rotation of the object>
I see you are in good hands. See you all tomorrow.
:-)
-
Cab, Wow.. :-D The "Round" is the name of that end of the block.. Its not really a diameter, yes you definitely described the task.. :lol:
-
How about a dynamic block? :D
I assume you probably have certain "valid" sizes. You could add a lookup to the block where you could pick from a drop down list choices. Or if nothing else the distance on the various sides could be restricted to "sane" values. (you can also set the 3 values via the properties window)
Not what you were looking for per se. Especially if you're using a version of autocad that doesn't support dyn blocks! :D
-
Quamper, I was thinking of creating a dynamic block but my users thought they would like this better.. I like the block, I will test both out with them.. Also, this is a good lesson for me to learn.. Thanks for the suggestion..
How about a dynamic block? :D
I assume you probably have certain "valid" sizes. You could add a lookup to the block where you could pick from a drop down list choices. Or if nothing else the distance on the various sides could be restricted to "sane" values. (you can also set the 3 values via the properties window)
Not what you were looking for per se. Especially if you're using a version of autocad that doesn't support dyn blocks! :D
-
Daron, Do I need to set more pnts like this, (/ pnt1 pnt2 pnt3 pnt4)? Or do I not need that?
And start you will.
First you need the user to supply:
point1 and point 2, then a height.
(setq pt1 (getpoint "\nSelect first point: "))
(setq pt2 (getpoint pt1 "\nSelect width: "))
etc.
Then ask the user to supply an angle or length of top line.
Take information, throw in some trig and the square part (name escapes me) is ready.
For the triangle you already have point1 and 2. To get the midpoint, use polar.
-
You might. It depends on how much will be needed by the program. I was just trying to get you started. Open the vlide and start typing and testing your code to see what it does. You can also access the help files easily from there.
-
Ok, I'm not sure if i'm understanding.. :? I'm not getting it to draw, I know that I don 't have enough points but I'm just trying to see if I could start it. I know this looks bad :|
(Defun C:SQR (); Draw Polyline [rectangle]
(command "layer" "M" "Equip" "C" "123" "Equip")
(setq oecho (getvar "cmdecho"))
(setq pt1 (getpoint "\nSelect first point: "))
(setq pt2 (getpoint pt1 "\nSelect Round width: "))
(setq pt3 (getpoint pt2 "\nSelect depth: "))
(command "pline" pt1 pt2 "")
(setvar "cmdecho" oecho)
(princ)
)
-
CECE
Here is a very basic code to get you started based on the pseudo code I posted.
There is no error checking & needs improvements.
(Defun C:SQR (/ SquareWidth RoundWidth Run ptBase ll lr ur ul um ent1 ent2)
(command "layer" "M" "Equip" "C" "123" "Equip" "")
(if
(and
(setq SquareWidth (getdist "\nEnter the Square Width: "))
(setq RoundWidth (getdist "\nEnter the Round Width: "))
(setq Run (getdist "\nEnter the lenght: "))
)
(progn
;; draw the object at 0,0 as the base point at middle of
;; the square end, then move to desired location.
(setvar "plinewid" 0)
(setq ptBase '(0 0)
ll (polar ptBase pi (/ SquareWidth 2.))
lr (polar ptBase 0.0 (/ SquareWidth 2.))
um (polar ptBase (/ pi 2) Run)
ul (polar um pi (/ RoundWidth 2.))
ur (polar um 0.0 (/ RoundWidth 2.))
)
(command "._pline" "_non" ll "_non" lr "_non" ur "_non" ul "_close")
(setq ent1 (entlast))
(command "._pline" "_non" ll "_non" um "_non" lr "")
(setq ent2 (entlast))
(command "_.change" ent2 "" "P" "C" "White" "")
(command "_.move" ent1 ent2 "" "_non" ptBase pause)
)
)
(princ)
)
-
Check out the following:
;;; PVSYMBOLS.LSP a program to insert in-line pipe valve
;;; symbols with or without trimming the line. Program by Tony Hotchkiss.
;;; 8-2-02, Revised local variables in (init) function
Gary
-
CECE
Here is a very basic code to get you started based on the pseudo code I posted.
There is no error checking & needs improvements.
(Defun C:SQR (/ SquareWidth RoundWidth Run ptBase ll lr ur ul um ent1 ent2)
(command "layer" "M" "Equip" "C" "123" "Equip" "")
(if
(and
(setq SquareWidth (getdist "\nEnter the Square Width: "))
(setq RoundWidth (getdist "\nEnter the Round Width: "))
(setq Run (getdist "\nEnter the lenght: "))
)
(progn
;; draw the object at 0,0 as the base point at middle of
;; the square end, then move to desired location.
(setvar "plinewid" 0)
(setq ptBase '(0 0)
ll (polar ptBase pi (/ SquareWidth 2.))
lr (polar ptBase 0.0 (/ SquareWidth 2.))
um (polar ptBase (/ pi 2) Run)
ul (polar um pi (/ RoundWidth 2.))
ur (polar um 0.0 (/ RoundWidth 2.))
)
(command "._pline" "_non" ll "_non" lr "_non" ur "_non" ul "_close")
(setq ent1 (entlast))
(command "._pline" "_non" ll "_non" um "_non" lr "")
(setq ent2 (entlast))
(command "_.change" ent2 "" "P" "C" "White" "")
(command "_.move" ent1 ent2 "" "_non" ptBase pause)
)
)
(princ)
)
Alan
I can use this, thanks for the heads up.
Gary
-
CECE
Here is a very basic code to get you started based on the pseudo code I posted.
There is no error checking & needs improvements.
(Defun C:SQR (/ SquareWidth RoundWidth Run ptBase ll lr ur ul um ent1 ent2)
(command "layer" "M" "Equip" "C" "123" "Equip" "")
(if
(and
(setq SquareWidth (getdist "\nEnter the Square Width: "))
(setq RoundWidth (getdist "\nEnter the Round Width: "))
(setq Run (getdist "\nEnter the lenght: "))
)
(progn
;; draw the object at 0,0 as the base point at middle of
;; the square end, then move to desired location.
(setvar "plinewid" 0)
(setq ptBase '(0 0)
ll (polar ptBase pi (/ SquareWidth 2.))
lr (polar ptBase 0.0 (/ SquareWidth 2.))
um (polar ptBase (/ pi 2) Run)
ul (polar um pi (/ RoundWidth 2.))
ur (polar um 0.0 (/ RoundWidth 2.))
)
(command "._pline" "_non" ll "_non" lr "_non" ur "_non" ul "_close")
(setq ent1 (entlast))
(command "._pline" "_non" ll "_non" um "_non" lr "")
(setq ent2 (entlast))
(command "_.change" ent2 "" "P" "C" "White" "")
(command "_.move" ent1 ent2 "" "_non" ptBase pause)
)
)
(princ)
)
Alan, it's cool
+100%
~'J'~
-
Thank you Sirs. 8-)
-
CAB,
Thanks.. That works great! I'm just trying to understand how you did that..
(Defun C:SQRR (/ SquareWidth RoundWidth Run ptBase ll lr ur ul um ent1 ent2)
those are all the variables?
-
Yes those are the local variables.
This is just starter routine that needs some error traps.
-
This is what I had in mind.
;; CAB @ TheSwamp.org 06/05/2008
(Defun C:SQR (/ SquareWidth RoundWidth Run ptBase ll lr ur ul um acDoc obj1 obj2
err lyrobj LayerName
)
(vl-load-com)
;; CAB 05/31/07
(defun activespace (doc)
(if (or (= acmodelspace (vla-get-activespace doc))
(= :vlax-true (vla-get-mspace doc))
)
(vla-get-modelspace doc)
(vla-get-paperspace doc)
)
)
(defun MakePline (space point-list)
(vlax-invoke space
'AddLightWeightPolyline
(apply 'append point-list) ; 2D point list
)
)
;; returns nil if make failed
(defun MakeLayer (lyrname acDoc / lyrobj)
(vl-load-com)
(if
(not
(vl-catch-all-error-p
(setq lyrobj
(vl-catch-all-apply
'vla-add
(list (vla-get-layers acDoc) lyrname))
)
)
)
lyrobj
)
)
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
;; Create the layer
(if (setq lyrobj (MakeLayer "Equip" acDoc))
(progn
(vla-put-color lyrobj "123")
(vlax-release-object lyrobj)
(setq LayerName "Equip")
)
)
(if
(and
(setq SquareWidth (getdist "\nEnter the Square Width: "))
(setq RoundWidth (getdist "\nEnter the Round Width: "))
(setq Run (getdist "\nEnter the lenght: "))
)
(progn
;; draw the object at 0,0 as the base point at middle of
;; the square end, then move to desired location.
(setvar "plinewid" 0)
(setq ptBase '(0 0)
ll (polar ptBase pi (/ SquareWidth 2.))
lr (polar ptBase 0.0 (/ SquareWidth 2.))
um (polar ptBase (/ pi 2) Run)
ul (polar um pi (/ RoundWidth 2.))
ur (polar um 0.0 (/ RoundWidth 2.))
)
(if (setq obj1 (MakePline (activespace acDoc) (list ll lr ur ul)))
(progn
(vla-put-Closed Obj1 :vlax-true)
(and LayerName (vla-put-Layer Obj1 LayerName))
;;(vla-put-Closed PolObj :vlax-true)
;;(vla-put-Color PolObj AcYellow)
;;(vla-put-Linetype PolObj "HIDDEN")
(if (setq obj2 (MakePline (activespace acDoc) (list ll um lr)))
(progn
(and LayerName (vla-put-Layer Obj2 LayerName))
(vla-put-Color Obj2 AcWhite)
(setq err (vl-catch-all-apply
'vl-cmdf
(list "_.move"
(vlax-vla-object->ename obj1)
(vlax-vla-object->ename obj2)
"" "_non" ptBase pause))
)
)
)
(if (< (distance ptBase (getvar "lastpoint")) 0.000001)
;; objects were not moved, so erase them
(progn
(and obj1 (vla-erase obj1))
(and obj2 (vla-erase obj2))
)
)
)
)
)
)
(princ)
)
-
Here is another version where you select the base point of the object.
;; CAB @ TheSwamp.org 06/05/2008
(Defun C:SQR (/ SquareWidth RoundWidth Run ptBase ll lr ur ul um acDoc obj1 obj2
err lyrobj LayerName pp activespace MakePline MakeLayer
)
(vl-load-com)
;; CAB 05/31/07
(defun activespace (doc)
(if (or (= acmodelspace (vla-get-activespace doc))
(= :vlax-true (vla-get-mspace doc))
)
(vla-get-modelspace doc)
(vla-get-paperspace doc)
)
)
(defun MakePline (space point-list)
(vlax-invoke space
'AddLightWeightPolyline
(apply 'append point-list) ; 2D point list
)
)
;; returns nil if make failed
(defun MakeLayer (lyrname acDoc / lyrobj)
(vl-load-com)
(if
(not
(vl-catch-all-error-p
(setq lyrobj
(vl-catch-all-apply
'vla-add
(list (vla-get-layers acDoc) lyrname))
)
)
)
lyrobj
)
)
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
;; Create the layer
(if (setq lyrobj (MakeLayer "Equip" acDoc))
(progn
(vla-put-color lyrobj "123")
(vlax-release-object lyrobj)
(setq LayerName "Equip")
)
)
(if
(and
(setq SquareWidth (getdist "\nEnter the Square Width: "))
(setq RoundWidth (getdist "\nEnter the Round Width: "))
(setq Run (getdist "\nEnter the lenght: "))
)
(progn
(initget "0 1 2 3 4 5")
(cond
((setq pp (getkword "\nRef Point on Duct.[0=MB 1=LL 2=LR 3=UR 4=UL 5=UM]<0>")))
((setq pp "0"))
)
;; draw the object at 0,0 as the base point at middle of
;; the square end, then move to desired location.
(setvar "plinewid" 0)
(setq ptBase '(0 0)
ll (polar ptBase pi (/ SquareWidth 2.))
lr (polar ptBase 0.0 (/ SquareWidth 2.))
um (polar ptBase (/ pi 2) Run)
ul (polar um pi (/ RoundWidth 2.))
ur (polar um 0.0 (/ RoundWidth 2.))
)
;; redefine pp as the pick point
(setq pp (eval (cdr (assoc pp '(("0" . ptBase)("1" . ll)("2" . lr)
("3" . ur)("4" . ul)("5" . um))))))
(if (setq obj1 (MakePline (activespace acDoc) (list ll lr ur ul)))
(progn
(vla-put-Closed Obj1 :vlax-true)
(and LayerName (vla-put-Layer Obj1 LayerName))
;;(vla-put-Closed PolObj :vlax-true)
;;(vla-put-Color PolObj AcYellow)
;;(vla-put-Linetype PolObj "HIDDEN")
(if (setq obj2 (MakePline (activespace acDoc) (list ll um lr)))
(progn
(and LayerName (vla-put-Layer Obj2 LayerName))
(vla-put-Color Obj2 AcWhite)
(vl-catch-all-apply
'vl-cmdf
(list "_.move"
(vlax-vla-object->ename obj1)
(vlax-vla-object->ename obj2)
"" "_non" pp pause))
(if (> (distance ptBase (getvar "lastpoint")) 0.001)
(vl-catch-all-apply
'vl-cmdf
(list "_.rotate"
(vlax-vla-object->ename obj1)
(vlax-vla-object->ename obj2)
"" "_non" (getvar "lastpoint") pause))
)
)
)
(if (< (distance ptBase (getvar "lastpoint")) 0.000001)
;; objects were not moved, so erase them
(progn
(and obj1 (vla-erase obj1))
(and obj2 (vla-erase obj2))
)
)
)
)
)
)
(princ)
)
-
Hey CAB... With the one that you have the base point set to (0 0)
;; draw the object at 0,0 as the base point at middle of
;; the square end, then move to desired location.
(setvar "plinewid" 0)
(setq ptBase '(0 0) <------ Can i change this to be upper left, like this : (setq ptBase '(ul)
?
-
By the way, the code works great. Yeah, it would of taking me a long time to get this one... Thank you, I was so stuck.
-
You're welcome.
If you wnat to move based on the ul change this
(list "_.move"
(vlax-vla-object->ename obj1)
(vlax-vla-object->ename obj2)
"" "_non" [color=red]ptBase[/color] pause))
To this
(list "_.move"
(vlax-vla-object->ename obj1)
(vlax-vla-object->ename obj2)
"" "_non" [color=red]ul[/color] pause))
-
Very nice... :lol: that is perfect