Jump to content

Automatically plot based on block definition


Maverik123

Recommended Posts

I am a beginner in autocad lisp. I tried to create one program by browsing various topics and Internet search. I want to plot automatically based block definition. We use an, a3 title blocks as blocks in autocad. I want to use this definition and plot. Below is the code

It is giving me error: bad function.  Can someone please help me to resolve this issue??

(defun C:PLOTME ()

(if (setq ss (ssget "_X" '(0 . "INSERT") (2. "A4-STD")))

(progn 

(setq i 0)

(while setq ent (ssname ss (setq i (1+ i)))

(setq e (entget ss1))

(setq pt1 (cdr (assoc 10 e)))        

(setq xval (rtos (car pt1) 2))

(setq yval (rtos (cadr pt1) 2))

(setq zval (rtos (caddr pt1) 2))

(setq pt2 '(xval yval))

(setq xval (1000+ xval))

(setq yval (1000+ yval))

(setq pt3 '(xval yval))

(command "plot" "Y" "MODEL" "PDFCreator" "A4" "Millimeters" "Portrait" "No" "Window" pause pause "FIT" "center" "Y" "DDSHIPCON 2018.ctb" "Y" "N" "N" "N" "Y")

); while

);progn

); if

); end function

 

 

Link to comment
Share on other sites

Welcome on CadTutor

 

check your ssget , your filter should be 

(setq ss (ssget "_X" '((0 . "INSERT") (2. "A4-STD"))))

 

both your 0 and 2 group should be in a list

Edited by rlx
Link to comment
Share on other sites

a couple of other things to look at as well......

 

I might be wrong with this but this version works better on my CAD - compare RLX and my offerings to your version to see the changes.

 

 

(defun C:PLOTME ( / )
  (if (setq ss (ssget "_X" '((0 . "INSERT")(2 . "A4-STD"))))
    (progn 
      (setq i -1) ;;start at -1 so it becomes 0 at next line
      (while (setq ent (ssname ss (setq i (1+ i))) ) ;;bracket needed before setq and at end of setq details
        (setq e (entget ent)) ;;ss1 didn't exist
        (setq pt1 (cdr (assoc 10 e)))
        (setq xval (rtos (car pt1) 2))
        (setq yval (rtos (cadr pt1) 2))
        (setq zval (rtos (caddr pt1) 2))
        (setq pt2 (list xval yval)) ;;using list here a ' will just put in exactly as you type, list will evaluate what is there
        (setq xval (rtos (+ 1000 (atof xval)))) ;;xval, yval are texts from rtos above, change to numbers and back to text
        (setq yval (rtos (+ 1000 (atof yval))))
        (setq pt3 (list xval yval))
        (command "plot" "Y" "MODEL" "PDFCreator" "A4" "Millimeters" "Portrait" "No" "Window" pause pause "FIT" "center" "Y" "DDSHIPCON 2018.ctb" "Y" "N" "N" "N" "Y") ;;and you don't use your points here!!
      ); while
    );progn
  ); if
); end function

 

Edited by Steven P
Corrected code
Link to comment
Share on other sites

You say use a A3 title block then choose a A4 size ?  Also depending on pdf device "Iso full bleed A3 (420.00 x 297.00 MM)" this is correct description of a A3 sheet.

 

Another suggestion if your title block is in layouts then use something like this it will plot all or a range of layouts for you. Its setup for a A1 title block plotting to a A3.

 

;Plots layouts by range
; By Alan H Feb 2014
(defun AH:pltlays ( / lay numlay numend)
(SETVAR "PDMODE" 0)

(setvar "fillmode" 1)
(setvar "textfill" 1)

(setq alllays (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
(setq count (vla-get-count alllays))
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq vals (AH:getvalsm  (list "Enter plot range" "Enter start tab number" 6 4 "1" "Enter end tab number" 6 4 (RTOS COUNT 2 0))))

(setq numlay (atoi (nth 0 vals)))
(setq numend (atoi (nth 1 vals)))

(setq len (+ (- numend numlay) 1))

(setq dwgname (GETVAR "dwgname"))
(setq lendwg (strlen dwgname))
(setq dwgname (substr dwgname 1 (- lendwg 4)))

(repeat len
(vlax-for lay alllays
(if (= numlay (vla-get-taborder lay))
  (setvar "ctab" (vla-get-name lay))
) ; if
(setq pdfname (strcat (getvar "dwgprefix") "pdf\\" dwgname "-" (getvar "ctab")))

) ; for
(setq lay nil)
(setvar "textfill" 1)
(setvar "fillmode" 1)
    (COMMAND "-PLOT"  "Y"  "" "DWG To PDF"
	       "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  "-6,-6" "807,560" "1=2"  "C"
	       "y" "Acad.ctb" "Y"	"n" "n" "n" pdfName "N" "y"
    )
    
(setq numlay (+ numlay 1))
) ; end repeat
) ; defun

(AH:pltlays)

Multi GETVALS.lsp

Link to comment
Share on other sites

Dear gents,

 

Thanks for your reply. I changed the code considerably doing some research. Pfb modified code 

(defun C:PLOTME ()

(setq n  (getint "\nEnter Number of Steps : "))

(if (setq ss (ssget "x" '((0 . "insert") (2 . "A4-STD"))))

(progn

(repeat n

(setq i (sslength ss))

               

(setq px (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))))

(setq pt2 (list (car px) (cadr px)))

(setq aa (atof (rtos (car px) 2)))

(setq bb (atof (rtos (cadr px) 2)))

(setq nx (+ aa 1000))

(setq ny (+ bb 1000))

(setq pt3 (list nx ny))

                                                               

(command "plot" "Y" "MODEL" "PDFCreator" "A4" "Millimeters" "Portrait" "No" "Window" sp1 sp2 "FIT" "center" "Y" "DDSHIPCON 2018.ctb" "Y" "N" "N" "N" "Y")

(PRINC)

); repeat



);progn

 

I am still not able to crack it. It is giving following error

Enter a layout name or [?] <Model>: MODEL Enter an output device name or [?] <None>: PDFCreator Enter paper size or [?] <A4>: A4 Enter paper units [Inches/Millimeters] <Inches>: Millimeters Enter drawing orientation [Portrait/Landscape] <Landscape>: Portrait Plot upside down? [Yes/No] <No>: No Enter plot area [Display/Extents/Limits/View/Window] <Display>: Window Enter lower left corner of window <0.000000,0.000000>:

Command:

Command: FIT Unknown command "FIT".  Press F1 for help.

Command: center Unknown command "CENTER".  Press F1 for help.

Command: Y Unknown command "Y".  Press F1 for help.

Command: DDSHIPCON 2018.ctb Unknown command "CTB".  Press F1 for help.

Command: Y Unknown command "Y".  Press F1 for help.

Command: N Unknown command "N".  Press F1 for help.

Command: N Unknown command "N".  Press F1 for help.

Command: N Unknown command "N".  Press F1 for help.

Command: Y Unknown command "Y".  Press F1 for help.

 

This means points sp1 and sp2 is null. I tried to use prompt and print all values,  it is giving me error " bad argued type: string 34372.0" This 34372 is x value of the first block. I am not sure how to correct it.

 

Please note above is only for testing purpose. Idea is to use block coordinates and define two points for Window plot. I will add addition and subtraction to this block coordinates to get the desired points. Once I get desired point, I will use them in plot, so as to get correct plot I want. Any help is greatly appreciated. Thanks a lot for educating me

 

Link to comment
Share on other sites

Finally some meaningful results. Thanks guys for your time

 

(defun C:PLOTME ()

(setq n  (getint "\nEnter Number of Steps : "))

(if (setq ss (ssget "x" '((0 . "insert") (2 . "A4-STD"))))

(progn

(setq i -1)

(repeat n

(setq px (cdr (assoc 10 (entget (ssname ss (setq i (1+ i)))))))

(setq aa (atof (rtos (car px) 2 4)))

(setq bb (atof (rtos (cadr px) 2 4)))

(setq nx (rtos (- aa 34355.3919) 2 4))

(setq ny (rtos (- bb 77165.1662) 2 4))

(setq mx (rtos (- aa 2855.3919) 2 4))

(setq my (rtos (- bb 32576.5481) 2 4))

(setq sp2 (strcat nx "," ny))

(setq sp3 (strcat mx "," my))

(princ sp2)

(princ sp3)                         

(command "plot" "Y" "MODEL" "PDFCreator" "A4" "Millimeters" "Portrait"

                                "No" "Window" sp2 sp3 "FIT" "center" "Y" "DDSHIPCON 2018.ctb" "Y" "N" "N" "N" "Y")

(PRINC)

); repeat

 

);progn

 

);if

(princ)

); end function

  • Like 1
Link to comment
Share on other sites

I'll get in here quick - someone else will - if you put your future code in between the code tags that gives it the grey background and is a bit easier to read - code tags, click the <> button above in the message header and paste in the pop up box.

 

Glad it is all working

Link to comment
Share on other sites

If the title block is in layouts go back and have a look at what I posted, it can plot like start at layout3 till layout 5. You just need to change the code to match the correct plotter name, size ctb, scale etc. Does not need "Model"

 

image.png.6ff8baf6bfb881cdde9e0a1c144dedc2.png

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...