CAD Forums > CAD General

Macro Help

(1/2) > >>

ML:
Hello,

I developed this little macro (see below) here that is really kind of cool.

If you are in Paperspace, you can initiate this macro, select your mview viewport and it will copy it into Model Space as a Block Reference and scale it up for you at the proper multiplier, in this case 48 because I am plotting at 1/4"=1'

Anyhow, After the pasteblock part is done, it wants to put it onto the current layer. This is no good, so I needed to tell AutoCAD to make defpoints current just prior to the paste insertion.

At the end of this macro needs to be more code that tells AutoCAD to make layer 0 current.  I did try -layer;s;0;; at the end but I am still having no luck. Any suggestions?

Thank you

Mark



--- Code: ---^C^Ccopyclip;\;(setvar "tilemode" 1);-layer;s;defpoints;;pasteblock;scale;48;

--- End code ---

ronjonp:

--- Code: ---^C^Ccopyclip;\;(setvar "tilemode" 1);-layer;m;defpoints;;pasteblock;scale;48;\(setvar 'clayer "0");
--- End code ---


I changed the layer set to layer make in case the layer did not exist. I also put a slash after the block was scaled to allow for insertion, then the layer is set to 0.

Ron

ML:
[/code]
^C^Ccopyclip;\;(setvar "tilemode" 1);-layer;s;defpoints;;pasteblock;scale;48;(setvar 'clayer "0");
[/code]


Hey Ron,

That is very good but not quite it. If I do the below as you are suggesting, then I am no longer being prompted in Model space for an insertion point, instead it just drops the block randomly. If I do it again, then it drops the next one right on top of the last one and so on. Can you think of a way to write it so that I will still be prompted for an insertion point?

Thanks

Mark

ML:
Hey Ron

I missed the backslash at the end of 48;

48;\(setvar 'clayer "0")  was perfect!

It works like a charm now

Hey! By using this, you will always have your outer most drawing limits set for you in Model Space

Thank you very much!

Mark

ELOQUINTET:
ml just out of curiousity why don't you try this it would seem like a better idea to have it draw a pline than create a block if i read your post correctly anyhow try this works great for what you wanna do i think.


--- Code: ---               ;Tip1687:   VPLIM.LSP     Pspace Limits in Mspace (c)2001, Murray Clack

               ;VPLIM.lsp draws the limits of a Paperspace Viewport Boundary in MODELSPACE
               ;VP - Get ViewPort object
               ;HT - Get Outside HeighT of Viewport
               ;WD - Get Oustide WiDth of Viewport
               ;VN - Get Viewport Number
               ;CTR - Get CenTeR of Viewport
               ;CTRX - Caluculate X of Viewport CenTeR
               ;CTRY - Caluculate Y of Viewport CenTeR
               ;VS - Get View Size of viewport
               ;XP - Calculate XP factor of viewport
               ;IW - Calculate Width of viewport
               ;BL - Calculate Bottom Left corner of viewport
               ;BR - Calculate Bottom Right corner of viewport
               ;TR - Calculate Top Right corner of viewport
               ;TL - Calculate Top Left corner of viewport
               ;PW - Save PlineWid
               ;OS - Save OSmode



               ;start function and define variables
(defun
     C:VPL
          (/ VP HT   WD VN CTR CTRX CTRY VS XP IW BL   BR TR TL PW OS)

               ;turn off command echoing
  (setvar "cmdecho" 0)

               ;save current layer as "clay"
  (setq clay (getvar 'clayer))

               ;make current layer defpoints
  (command "_.layer" "m" "Defpoints" "")

               ;enter pspace
  (command ".pspace")

               ;select viewport boundary
  (setq   VP
    (entget
      (car

        (entsel
          "\nSelect Viewport to Draw Boundary
             in "
        ) ;_ end of entsel
      ) ;_ end of car
    ) ;_ end of entget
  ) ;_ end of setq

               ;Get Viewport height with
  (setq HT (cdr (assoc 41 VP)))

               ;Get Viewport width with
  (setq WD (cdr (assoc 40 VP)))

               ;Get Viewport Number
  (setq VN (cdr (assoc 69 VP)))

               ;enter mspace
  (command ".mspace")

               ;set correct viewport
  (setvar "cvport" VN)

               ;set UCS to View
  (command ".ucs" "v")

               ;Get VIEWCTR store as CTR
  (setq CTR (getvar "viewctr"))

               ;Get X of CTR
  (setq CTRX (car CTR))

               ;Get Y of CTR
  (setq CTRY (cadr CTR))

               ;Get inside Viewport height
  (setq VS (getvar "viewsize"))

               ;Get XP Factor with HeighT / View Size
  (setq XP (/ HT VS))

               ;Get inside width of Viewport by
  (setq IW (* (/ VS HT) WD))

               ;Find four corners of Viewport
  (setq BL (list (- CTRX (/ IW 2)) (- CTRY (/ VS 2))))

  (setq BR (list (+ CTRX (/ IW 2)) (- CTRY (/ VS 2))))

  (setq TR (list (+ CTRX (/ IW 2)) (+ CTRY (/ VS 2))))

  (setq TL (list (- CTRX (/ IW 2)) (+ CTRY (/ VS 2))))

               ;Save current pline width
  (setq PW (getvar "plinewid"))

               ;Set Pline width to zero
  (setvar "plinewid" 0)

               ;Save current osmode
  (setq OS (getvar "osmode"))

               ;Draw pline inside border
  (command ".pline" BL BR TR TL "c")

               ;Restore pline width back
  (setvar "plinewid" PW)

               ;Restore UCS back
  (command ".ucs" "p")

               ;Restore osmode
  (setvar "osmode" OS)

               ;Restore curernt layer
  (setvar "clayer" clay)

               ;Clean up command prompt
  (princ)

               ;Go Back To Papserspace
  (command ".pspace")

)               ;The End!
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version