Jump to content

Recommended Posts

Posted

Hi everyone,

I'm  trying to plot a rectangle via autolisp, so I wrote some codes to get current device and make a plot by window item and left , right corner points, 

 

(setq	cplot (vla-get-ActiveLayout
		(vla-get-activedocument
		  (vlax-get-acad-object)
		)
	      )
  )

(setq dev (vla-get-ConfigName cplot))

(vla-put-PlotType cplot acWindow)                         ;;Set window option to plot area
(setq pt1 (getpoint "Enter a point: "))  		 	      ;;Get upper-right point of rectabgle
(setq pt2 (getpoint "Enter a point: "))   				  ;;Get lower-left point of rectabgle
(vlax-invoke-method cplot 'setwindowtoplot pt1 pt2)

(command "_.-PLOT"
	     "No"			
	     "Model"				
	     ""					 
	     dev			 
	     "No"    ;;plot without save file
	     "No"    				 
	     "Yes"			
    )

But it gives this error :

Enter a point: ; error: lisp value has no coercion to VARIANT with this type.

Posted
1 hour ago, amir0914 said:

Hi everyone,

I'm  trying to plot a rectangle via autolisp, so I wrote some codes to get current device and make a plot by window item and left , right corner points, 

 

But it gives this error :

Enter a point: ; error: lisp value has no coercion to VARIANT with this type.

 

(vlax-3d-point pt1) as well as pt2 

WCS

Posted
30 minutes ago, hanhphuc said:

vlax-3d-point pt1)

error: Automation Error. Incorrect number of elements in SafeArray

 

 (setq	cplot (vla-get-ActiveLayout
		(vla-get-activedocument
		  (vlax-get-acad-object)
		)
	      )
  )

  (setq dev (vla-get-ConfigName cplot))

  (vla-put-PlotType cplot acWindow)
  (setq pt1 (getpoint "Enter a point: "))
  (setq pt2 (getpoint "Enter a point: "))
  (vlax-invoke-method
    cplot
    'setwindowtoplot
    (vlax-3d-point pt1)
    (vlax-3d-point pt2)
  )

  (command "_.-PLOT" "No" "Model" "" dev "No" "No" "Yes")

 

Posted (edited)

 

 

4 hours ago, amir0914 said:

error: Automation Error. Incorrect number of elements in SafeArray

 

:sweat: sorry i assume variant was 3d point..

 

so try to debug yourself , according to developer documentation it requires 2d doubles, ie: x,y not x,y,z

read the article 

 

Quote

 

object.SetWindowToPlot(LowerLeft, UpperRight)

 

Object

Layout, PlotConfiguration
The object or objects this method applies to.

LowerLeft

Variant (two-element array of doubles); input-only
The X and Y values for the lower-left window.

UpperRight

Variant (two-element array of doubles); input-only
The X and Y values for the upper-right window.

 

Remarks

The window coordinates are taken from the origin.

The units for these values are specified by the PaperUnits property. 

The PlotType property must be set to acWindow for these coordinates to be used for the plot.

 

 

 

vlax-2d-point is built-in function BCAD

(defun vlax-2d-point (pt)
  (vlax-make-variant
    (vlax-safearray-fill
    (vlax-make-safearray vlax-vbDouble '(0 . 1))
    (list (car pt) (cadr pt))
    )
    )
  )


 

eg. call

 

      
(vlax-2d-point p1) 
;#<variant 8197 ...> 
(mapcar 'vlax-2d-point (list p1 p2))     
;( #<variant 8197 ...>  #<variant 8197 ...> )

      
 

hint

trans & acWindow

 

Edited by hanhphuc
vlax-2d-point
  • Like 1
Posted (edited)

Thanks, it's working without any error, but the exported PDF or print is only blank page. I think convert  the coordinates is wrong. 

(defun c:plt ()

  (setq	cplot (vla-get-ActiveLayout
		(vla-get-activedocument
		  (vlax-get-acad-object)
		)
	      )
  )

  (setq dev (vla-get-ConfigName cplot))

  (vla-put-PlotType cplot acWindow)
  (setq pt1 (getpoint "Enter a point: "))
  (setq pt2 (getpoint "Enter a point: "))

  (vlax-invoke-method
    cplot
    'setwindowtoplot
    (vlax-2d-point pt1)
    (vlax-2d-point pt2)
  )

  (vla-put-CenterPlot cplot "1")

  (command "_.-PLOT"
	   "No"
	   "Model"
	   ""
	   dev
	   (strcat (getvar "DWGPREFIX") "1.pdf")
	   "No"
	   "Yes"
  )

)

(defun vlax-2d-point (pt)
  (vlax-make-variant
    (vlax-safearray-fill
      (vlax-make-safearray vlax-vbDouble '(0 . 1))
      (list (car pt) (cadr pt))
    )
  )
)

 

Edited by amir0914
Posted (edited)

Quick glance and you are passing a variant to vlax-invoke which does not work ( not tested )

  ;; Use this
  (vla-setwindowtoplot cplot (vlax-2d-point pt1) (vlax-2d-point pt2))
  ;; Or this
  (vlax-invoke
    cplot
    'setwindowtoplot
    (list (car pt1) (cadr pt1))
    (list (car pt2) (cadr pt2))
  )

Other issues too but have to run...

(vla-put-centerplot cplot "1") ??

 

Edited by ronjonp
  • Thanks 1
Posted
4 hours ago, amir0914 said:

Thanks, it's working without any error, but the exported PDF or print is only blank page. I think convert  the coordinates is wrong. 

 

 

11 hours ago, hanhphuc said:

 

hint

trans & acWindow

 

 

missed a hint? :) 

untested (trans p 0 2) (trans p 1 2)  (trans p 2 3) (trans p 3 2) etc..

      
 (apply
  'vla-SetWindowToPlot
  (cons cplot (mapcar '(lambda (p) (vlax-2d-point (trans p 1 2))) (list p1 p2)))
  )
  

is debugging fun? 

 

 

3 hours ago, ronjonp said:

Quick glance and you are passing a variant to vlax-invoke which does not work ( not tested )

(list (car pt1) (cadr pt1))

(list (car pt2) (cadr pt2))

 

🍻  😎

 

 

 

 

 

 

 

  • Like 1
Posted (edited)

Here is a example of plot pdf using a window it has hard coded window points but change them to your pt1 pt2 etc as per second example scale can be FIT. Removes need for VL etc.

 

(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"
    )

(COMMAND "-PLOT"  "Y"  "" "DWG To PDF"
	       "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  pt1 pt2 "1=2"  "C"
	       "y" "Acad.ctb" "Y"	"n" "n" "n" pdfName "N" "y"
    )

If as you say have a rectangle a pline then can use the vertices of the pline so just pick pline one pick, corners are vertice 1 and 3

 

This can be automated to plot all rectangles on a model layout say by layer. Read as multiple title blocks in model space.Yeah have code.

Edited by BIGAL
  • Like 1
Posted (edited)
On 6/26/2020 at 4:47 AM, hanhphuc said:

 

 

missed a hint? :) 

untested (trans p 0 2) (trans p 1 2)  (trans p 2 3) (trans p 3 2) etc..


      
 (apply
  'vla-SetWindowToPlot
  (cons cplot (mapcar '(lambda (p) (vlax-2d-point (trans p 1 2))) (list p1 p2)))
  )
  

 

Thank you so much, that was great. 🌹

 

Edited by amir0914
Posted
On 6/26/2020 at 5:02 AM, BIGAL said:

Here is a example of plot pdf using a window it has hard coded window points but change them to your pt1 pt2 etc as per second example scale can be FIT. Removes need for VL etc.

 


(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"
    )

(COMMAND "-PLOT"  "Y"  "" "DWG To PDF"
	       "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  pt1 pt2 "1=2"  "C"
	       "y" "Acad.ctb" "Y"	"n" "n" "n" pdfName "N" "y"
    )

If as you say have a rectangle a pline then can use the vertices of the pline so just pick pline one pick, corners are vertice 1 and 3

 

This can be automated to plot all rectangles on a model layout say by layer. Read as multiple title blocks in model space.Yeah have code.

Thanks BIGAL, but if I change any option of plot setting, I have to change it from codes, for example size paper, or scale, and I want to connect program to current plotter, no change manual in codes.

Posted

Have a look at plotting by Maratovich he has an extensive plot routine.

 

For me always using layouts and title blocks at true scale removed all problems, the user would choose which option to run  A1, A3, PDF etc we basically only had 3 options. AS A3 is a 1/2 size A1 our title block was true A1.

Posted

Building on what BigAl had, in my PDF plotting routine I define all the plot variables earlier in the routine, and then bring them together in the (command "plot" … ) line. I control all of this with a DCL box for user inputs but you could use the LISP routine to work it all out too.

 

So I have:

 

;;Plot model space
      (IF (= (getvar "TILEMODE") 1)
        (progn
          (if (= plotarea "window")
(command "-plot" detailedplotconfiguration layoutname plottername papersize paperunits orientation plotupsidedown plotarea pause pause plotscale plotoffset plotwithplotstyles plotstyletablename plotwithlineweights shadeplotsetting writeplottofile saveplotsettings proceedwithplot)
           ) ;;end if
          (if (/= plotarea "window")
(command "-plot" detailedplotconfiguration layoutname plottername papersize paperunits orientation plotupsidedown plotarea plotscale plotoffset plotwithplotstyles plotstyletablename plotwithlineweights shadeplotsetting writeplottofile saveplotsettings proceedwithplot)
           ) ;; end if
        ) ;;end progn
      ) ;; end if

;;;;Plot paper space
      (IF (= (getvar "TILEMODE") 0)
        (progn
          (if (= plotarea "window")
            (progn
(command "-plot" detailedplotconfiguration layoutname plottername papersize paperunits orientation plotupsidedown plotarea pause pause plotscale plotoffset plotwithplotstyles plotstyletablename plotwithlineweights scalelineweights plotpaperspacefirst hidepaperspaceobjects writeplottofile saveplotsettings proceedwithplot)
            )
          )
          (if (/= plotarea "window")
            (progn
              (command "zoom" "all" "zoom" ".95x")
(command "-plot" detailedplotconfiguration layoutname plottername papersize paperunits orientation plotupsidedown plotarea plotscale plotoffset plotwithplotstyles plotstyletablename plotwithlineweights scalelineweights plotpaperspacefirst hidepaperspaceobjects writeplottofile saveplotsettings proceedwithplot)
            )
          )
        )
      )

Noting that plotarea is set to window if the user clicks on the 'plot window' check box in the DCL.

I found that I needed slightly different command line depends if the user was in paper or model space. All the other variables are either defined or worked out earlier in the routine. It all depends how much automation you want on the plotting how many of these are via user inputs or worked out in the LISP.

 

Might give you another idea of what you can do

Posted

Like Steven P pick 2 points then pop a dcl and just pick the correct settings, here is multi radio button.lsp example code.

 

(setq ansp (ah:butts but "V"   '("Choose printer " "  A3 laser" "  A1 Plotter" "  A3 PDF" "  A1 PDF" )))

(setq ansc (ah:butts but "V"   '("Choose scale" "  1:100" "  1:200" "  1:50" "  1:10" )))

(setq anss (ah:butts but "V"   '("Choose printer " " A4" "  A3 " "  A2" "  A1" )))

Multi radio buttons.lsp

 

  • Like 1

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...