Plotting blocks in modelspace

Plotting blocks in modelspace

WauterM.
Explorer Explorer
833 Views
3 Replies
Message 1 of 4

Plotting blocks in modelspace

WauterM.
Explorer
Explorer

Hello,

 

I am trying to rewrite a piece of code, originally intended to plot to a pdf, and make it print directly to the output device. 

( I don't know much, if anything about lisp) The point is that it looks for blocks (A4PLOT for example) in my selection set and then automatically prints them.

 

There is a block of code in the lisp that points to making a file and naming it I believe but I can't delete it without the code breaking, as of now it does not do anything at all.

 

Any advice by you Lispers?

 

This is the code so far:

 

(vl-load-com)
(defun c:PrintA4P (/ dwg file hnd i len llpt lst mn mx ss tab urpt)
    (if (setq ss (ssget "_P" '((0 . "INSERT") (2 . "A4PLOT"))))
        (progn
            (repeat (setq i (sslength ss))
                (setq hnd (ssname ss (setq i (1- i)))
                      tab (cdr (assoc 410 (entget hnd)))
                      lst (cons (cons tab hnd) lst)
                )
            )
			(setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
            (setq i 0)
            (foreach x lst
                (setq file (strcat (getvar 'DWGPREFIX)
                                   (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4))	
                                   "-"
                                   (itoa (setq i (1+ i)))
                                   ".pdf"
                           )
                )
                (if (findfile file)
                    (vl-file-delete file)
                )			
                (vla-getboundingbox (vlax-ename->vla-object (cdr x)) 'mn 'mx)
                (setq llpt (vlax-safearray->list mn)
                      urpt (vlax-safearray->list mx)
                      len  (distance llpt (list (car urpt) (cadr llpt)))
                )
                (command "-plot"
                         "yes"
                         (car x)
                         "KONICA MINOLTA C554 (v1)"
                         "A4"
                         "Millimeters"
                         "Portrait"
                         "No"
                         "Window"
                         llpt
                         urpt
                         "Fit"
                         "Center"
                         "yes"
                         "Monochrome.ctb"
                         "yes"
                         ""
                )
				(if (/= (car x) "Model")
                    (command "No" "No" file "No" "Yes")
                    (command
                        file
                        "No"
                        "Yes"
                    )
                )
            )
        )
    )
    (princ)
)

 

Wauter

 

0 Likes
834 Views
3 Replies
Replies (3)
Message 2 of 4

john.uhden
Mentor
Mentor

I may be mistaken, but 

(ssget "_P" ...) means select previous, as though there is already a current selection set.  Is that what you really want?

I didn't try out the rest, but the structure looks pretty good.

John F. Uhden

0 Likes
Message 3 of 4

WauterM.
Explorer
Explorer

Hi John,

 

First thank you for looking into it,

 

Yes this is as intended, at first the code would look for every instance of the block in my drawing but I need it to only plot the blocks that I allready have in a selection set.

 

I am still at a loss for why the code doesn't run at all though... ( I don't even get anything on the command line when I try to run the command)

 

Greets,

 

Wauter

0 Likes
Message 4 of 4

john.uhden
Mentor
Mentor

I don't see a local *error* function, so maybe you have a global one that does just a (princ).  Also, try turning on cmdecho.

My apologies for being ignorant of the command line version of plot.

Then there's the old Uhden method of including (setq ok 1) and counting to see where the code may have stopped.  I never did like using vlide, probably because I'm an old fart who started long before vlide.  Not that this old dog can't learn new tricks, but until I lose my right hand I see no reason to start being a lefty.  Then again, back in R2.6 on 286s, I taught everyone to use their left hand for the digitizing tablet so that their right hand was free to use the number pad.  Ah, that 16-button puck I had programmed to do a lot of quickie things, osnaps and such.  I still remember not having to look up the phone number... 1-800-CALCOMP.

John F. Uhden

0 Likes