Jump to content

Recommended Posts

Posted

Hi .I want to ask if someone have a lisp to calculate the area of layout print paper.

 

Thanks

Posted

hi tombu thanks for the reply. This lisp gives me the dimension of each layout,I want a lisp to culculate the area of the curent layout.

 

Thanks

Posted (edited)

Hi bigal . I need to calculate the printing cost for the current layout.

The first lisp code gives me the dimensions of all layouts . This lisp calculate the cost of the last layout . Can any one change it to calculate the cost of the current layout?

 

(defun c:test (/ lo wdt lg plotarea)
 (vl-load-com)
 (vlax-for lo (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
   (vla-getpapersize lo 'wdt 'lg)
   (setq plotarea (list wdt lg))
      (princ "\n")
   (princ (vla-get-name lo))
   (princ "\n\t\tPlot size - ")
(princ
     (if
       (zerop (rem (vla-get-plotrotation lo) 2))
       plotarea
     )
   )
 )
(setq area (/( * wdt lg) 1000000))
(setq pr (cond ((getreal  "\n The print cost €/sq.m (π.χ 2.30 €/sq.m monochrome  ή 3.50 €/sq.m color) : "))(2.30)))
(setq cost (* pr area))
(setq sx (cond ((getreal  "\n Give the number of copies (example 3) : "))(3)))
(setq scost (* sx cost))
 (textscr)
(princ (strcat 
                  "\n Calculations"
                  "\n --------------------------------------------------------------------------"                    
                   "\n dimension x = "
                    (rtos wdt 2 2)
                    " m"
                    "\n dimension y = "
                    (rtos lg 2 2)
                    " m"
                    "\n Area of the print paper = "
                    (rtos area 2 2)
                    " sq.m"
                    "\n Cost per drawing = "
                    (rtos cost 2 2)
                    " €"
                    "\n Total Cost of Printing = "
                    (rtos scost 2 2)
                    " €"
            )
     )

 (princ)
)

 

 

Thanks

Edited by prodromosm
Posted

I update the code but i still have the same problem.This lisp calculate the cost of the last layout

Posted

Try this revised code...

 

(defun c:test (/ lo wdt lg plotarea)
 (vl-load-com)
 ;(vlax-for lo (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
 (setq lo (vla-item (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (getvar 'CTAB)))
   (vla-getpapersize lo 'wdt 'lg)
   (setq plotarea (list wdt lg))
      (princ "\n")
   (princ (vla-get-name lo))
   (princ "\n\t\tPlot size - ")
(princ
     (if
       (zerop (rem (vla-get-plotrotation lo) 2))
       plotarea
       (reverse plotarea); <<<<
     )
   )
 
(setq area (/( * wdt lg) 1000000))
(setq pr (cond ((getreal  "\n The print cost €/sq.m (p.? 2.30 €/sq.m monochrome  ? 3.50 €/sq.m color) : "))(2.30)))
(setq cost (* pr area))
(setq sx (cond ((getreal  "\n Give the number of copies (example 3) : "))(3)))
(setq scost (* sx cost))
 (textscr)
(princ (strcat 
                  "\n Calculations"
                  "\n --------------------------------------------------------------------------"                    
                   "\n dimension x = "
                    (rtos wdt 2 2)
                    " m"
                    "\n dimension y = "
                    (rtos lg 2 2)
                    " m"
                    "\n Area of the print paper = "
                    (rtos area 2 2)
                    " sq.m"
                    "\n Cost per drawing = "
                    (rtos cost 2 2)
                    " €"
                    "\n Total Cost of Printing = "
                    (rtos scost 2 2)
                    " €"
            )
     )

 (princ)
)

 

Henrique

Posted

@Henrique,

 

This:

(setq lo (vla-item (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (getvar 'CTAB)))

Could become:

(setq lo (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))

:thumbsup:

Posted

Perhaps the code could be shortened to:

(defun c:test ( / lay len lst num prc wid )
   (if (= 1 (getvar 'tilemode))
       (princ "\nCommand only available in paperspace.")
       (progn
           (initget 6)
           (setq prc (cond ((getreal "\nThe print cost €/sq.m <2.30 €/sq.m>: ")) (2.30)))
           (initget 6)
           (setq num (cond ((getint "\nNumber of copies <1>: ")) (1))
                 lay (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)))
           )
           (vla-getpapersize lay 'wid 'len)
           (if (zerop (rem (vla-get-plotrotation lay) 2))
               (setq lst (list wid len))
               (setq lst (list len wid))
           )
           (textscr)
           (princ
               (strcat
                   "\n Calculations for layout \"" (vla-get-name lay) "\""
                   "\n ------------------------------------------------------------"
                   "\n   Dimensions: " (rtos len 2 2) " mm x " (rtos wid 2 2) " mm"
                   "\n   Paper area: " (rtos (* len wid 1e-6) 2 2) " sq.m"
                   "\n Cost per dwg: " (rtos (* prc len wid 1e-6) 2 2) " €"
                   "\n   Total cost: " (rtos (* prc len wid num 1e-6) 2 2) " €"
                   "\n ------------------------------------------------------------"
               )
           )
       )
   )
   (princ)
)

Posted
@Henrique,

This:

(setq lo (vla-item (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (getvar 'CTAB)))

Could become:

(setq lo (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))

:thumbsup:

Hi Lee,

of course it is much more logical to get the 'activelayout' object... :)

My intente was to show to OP that we don't need to loop through each item in the 'Layouts' collection, just get one, the current one...

 

Cheers

Henrique

Posted
of course it is much more logical to get the 'activelayout' object... :)

My intente was to show to OP that we don't need to loop through each item in the 'Layouts' collection, just get one, the current one...

 

I understand Henrique - my apologies for interefering with the lesson for the OP :)

 

Lee

Posted
I understand Henrique - my apologies for interefering with the lesson for the OP :)

 

Lee

Lee,

no need for apologies.

Your comments, explanations and codes, are always welcome.:)

 

Cheers

Henrique

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