Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

draw using LISP

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Anonymous
2782 Views, 9 Replies

draw using LISP

I have attached herewith drafting flow for the drawing, i want script for the same process. please guide me please. i am new here & i have not much knowledge about LISP program.
ALSO PLEASE SEE BELOW I HAVE ATTACHED SCRIPT WHICH I HAVE WRITE FOR START.   

(defun c:panel ( / len wid pt1 pt2 pt3 pt4)
(setq pt1 (getpoint "\nPick lower left Corner"))
(setq Len (Getreal "\nEnter length"))
(setq wid (Getreal "\nWidth"))
(setq pt2 (polar Pt1 0.0 len))
(setq pt3 (polar pt2 (/ pi 2.0) wid))
(setq pt4 (polar pt3 pi len))
(command "pline" pt1 pt2 pt3 pt4 "c")
)
(C:panel)
 
 
9 REPLIES 9
Message 2 of 10
ВeekeeCZ
in reply to: Anonymous

That's pretty easy! But it takes some time, thinking and little effort. And the best thing about this task is that you would need to know very little of LISP programming to be able to do that all by yourself!

 

Revised workflow.

1) Get initial points using a (getcorner) function. (= do not draw a rectangle)

2) Calculate all the points you need from initial points. All means all - for extended corners, circle centers... all! You would need a (polar) function to use. Possibly also (car pnt), (cadr pnt) and (list x y z) functions to work with coordinates. Then you would need some loop, probably a (while) would be the best.

3) Generate all the linework using entmake functions. Minimum definitions are HERE . Or simply use (command "line"), but I wouldn't recommend that.

4) Calculate all points needed for dimensioning. Use (command "dimlinear" x y d). Turn off osnaps before! Points for extension line origins x a y you already have, so just a point for placing dimension text needed. Use a (polar) here as well.

 

So how many functions you need, 5?

 

5) come back if! you get stuck. Good luck!

 

 

 

Message 3 of 10
Anonymous
in reply to: ВeekeeCZ

Could you please provide me script .......Actually i have not much information & knowledge to do this. please ...........

Message 4 of 10
ВeekeeCZ
in reply to: Anonymous

Be specific. What information are you missing? What knowledge you cannot find in HELP?

Message 5 of 10
Anonymous
in reply to: ВeekeeCZ

Could you provide me sample scripts for any same object, like draw rectangle in spacific layer, offset to rectangle etc.

Message 6 of 10
ВeekeeCZ
in reply to: Anonymous

You really did not read what I've said, did you?!!

 

Here is something for you to get started.

(defun c:Panel (/ *error* osm eco lay :Line :DimAligned pt1 len wid pt2 pt3)

  ;; ---- SUBS ----------------------------------------------------------------

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if osm (setvar 'OSMODE osm))
    (if eco (setvar 'CMDECHO eco))
    (if lay (setvar 'CLAYER lay))
    (princ))

  
  (defun :Line (p1 p2 lay) (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2) (cons 8 lay))))
  (defun :DimAligned (p1 p2 dst) (command "_.DIMALIGNED" p1 p2 (polar p1 (+ (angle p1 p2) (/ pi 2)) dst)))

  ;; ---- MAIN ----------------------------------------------------------------


  ;; user input
  
  (if (and (setq pt1 (getpoint "\nPick lower left Corner: "))
	   (setq len (getdist "\nEnter length: "))
	   (setq wid (Getreal "\nWidth: ")))
    (progn

      
      ;; save sysvars
      (setq osm (getvar 'OSMODE)) 	(setvar 'OSMODE 0)
      (setq eco (getvar 'CMDECHO)) 	(setvar 'CMDECHO 1) ; turn 0 when is program final
      (setq lay (getvar 'CLAYER))


      
      ;; point calculation
      (setq pt2 (polar pt1 0. len))
      (setq pt3 (polar pt2 (/ pi 2.0) wid))


      
      ; layers
      (command "_.LAYER" "_T" "White" "_M" "White" "_Color" 7 "White" "") ; layers


      
      ;; draw linework
      (:line pt1 pt2 "White")

      

      ;; draw dims
      (:dimAligned pt1 pt2 -135.)

      ))

      (*error* "end")  ; restore all the sysvars
 
)
Message 7 of 10
CodeDing
in reply to: Anonymous

@Anonymous ,

 

Is this a consideration of what you're looking for? Maybe I don't understand why it needs to be more complicated than this?

Note: This assumes a base direction of EAST

(defun c:PANEL ( / )
(command "_.RECTANG" pause "_d" pause pause "non" (polar (getvar 'LASTPOINT) (* 0.25 pi) 1))
(princ)
);defun

Best,

~DD


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 8 of 10
CodeDing
in reply to: CodeDing

I did not see the attached dwg file. Please ignore my previous post! Lol


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 9 of 10
scot-65
in reply to: Anonymous

If you take note in message #6, there is a fundamental
programming structure to follow that is often overlooked
by *newbies*:

a) Gather User input [in his/her current environment].
b) Check for valid input.
c) Execute [including setting, then resetting system variables, etc.].

For message #6, the checking input part is in the form of an "IF".
What you have shown, checking for valid input does not exist.

By strategically isolating the input section from the execute section
(call it paranoia), it is possible to not employ any error handling!

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 10 of 10
Sea-Haven
in reply to: scot-65

This has been posted elsewhere as well maybe Theswamp.org as I provided further info re holes.

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report