Author Topic: autolisp exercise  (Read 8614 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
autolisp exercise
« on: January 09, 2006, 01:24:03 PM »
i have some free time for a couple days so i would like to convert a macro we have into lisp. the macro creates a border layer. then creates a viewport. it captures then last modelspace view then centers that view inside the viewport with the scale set to 1:2. i would like to be able to check to see if the layer is present and if it isn't create it. i just feel it's getting to complicated for a macro and would be much cleaner as a lisp. besides i need the excercise. so if anyone would like to help me out i'd really appreciate it. i don't want it written but some big hints on how to structure it would be nice.

^C^C_-LAYER;M;BORDER;C;251;;P;N;;;^C^C_MVIEW;\\;^C^C_CHANGE;L;;P;C;BYLAYER;LA;BORDER;;_.MSPACE;Z;O;L;;Z;S;1/2XP;.PSPACE;^C^C_LAYERP; ^M;

Crank

  • Water Moccasin
  • Posts: 1503
Re: autolisp exercise
« Reply #1 on: January 09, 2006, 01:36:11 PM »
Just curious... Why so much cancels in one macro?
Vault Professional 2023     +     AEC Collection

ELOQUINTET

  • Guest
Re: autolisp exercise
« Reply #2 on: January 09, 2006, 01:44:55 PM »
yeah the guy who wrote the macro was not very experienced and was under the impression everything had to be cancelled

T.Willey

  • Needs a day job
  • Posts: 5251
Re: autolisp exercise
« Reply #3 on: January 09, 2006, 01:48:18 PM »
Which way you want to go?
Lisp/VLisp?
ActiveX?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ELOQUINTET

  • Guest
Re: autolisp exercise
« Reply #4 on: January 09, 2006, 01:53:46 PM »
mmm...i think lisp or vlisp. i would say lisp being that it is the only thing i have limited knowledge of. i am very much a beginner so please be patient with me. i am looking through some lisp i have already trying to find an example of how to check for a given layer and if it's not present create it and set current

deegeecees

  • Guest
Re: autolisp exercise
« Reply #5 on: January 09, 2006, 01:56:36 PM »
yeah the guy who wrote the macro was not very experienced and was under the impression everything had to be cancelled

Did I write that?

 :-D

T.Willey

  • Needs a day job
  • Posts: 5251
Re: autolisp exercise
« Reply #6 on: January 09, 2006, 02:03:04 PM »
mmm...i think lisp or vlisp.
In that case, you want to look at the table funtions.  If you want to get complicated then you can use "entmake" for the layer (I think, but I don't use entmake all that often) if it doesn't exist, or just use the layer command to add it.
This should get you started.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: autolisp exercise
« Reply #7 on: January 09, 2006, 02:06:41 PM »
I'd start by framing in the functional outline in comments. I just bashed this out quick to give you an idea --

Code: [Select]
(defun c:foo ( )

    ;;  save the current layer

    ;;  make the border layer if it doesn't exist
   
    ;;  set the colors of the border layer
   
    ;;  make the border layer non printable
   
    ;;  set the current layer to the border layer
   
    ;;  set tilemode to 1
   
    ;;  switch to paperspace
   
    ;;  make a viewport, record it's viewport id
   
    ;;  switch to modelspace
   
    ;;  make the viewport we just made active (use the viewport id)
   
    ;;  zoom all, then 1/2 xp
   
    ;;  change back to paperspace
   
    ;;  set the active layer back to the one we started with

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Crank

  • Water Moccasin
  • Posts: 1503
Re: autolisp exercise
« Reply #8 on: January 09, 2006, 02:46:36 PM »
I think the TILEMODE must be 0.

Why not follow the macro?

Code: [Select]
(defun c:foo ()
(if (tblsearch "LAYER" "BORDER")
(setvar "CLAYER" "BORDER")
(vl-cmdf ".layer" "m" "BORDER" "C" "251" "" "P" "N" "" "")
)
(setvar "TILEMODE" 0); be sure that you start in a layout
(command ".mview" (getpoint "\nSelect rectangle of viewport...")(getcorner "to..." (getvar "LASTPOINT")))
(vl-cmdf ".chprop" "L" "" "c" "bylayer" "")
(vl-cmdf ".mspace")
(vl-cmdf ".zoom" "all")
(vl-cmdf ".zoom" ".5xp")
(vl-cmdf ".pspace")
(vl-cmdf ".layerp")
(princ)
)
Vault Professional 2023     +     AEC Collection

ELOQUINTET

  • Guest
Re: autolisp exercise
« Reply #9 on: January 09, 2006, 03:28:03 PM »
foo that worked if i only had 1 object in my drawing which is never the case. i modified it to work like the macro does and seem to have gotten it. i have printed out the tblsearch and vl-cmdf from help to look at as well. here's what i got:
thanks alot for the help :)

Code: [Select]
(defun c:foo ()
(if (tblsearch "LAYER" "BORDER")
(setvar "CLAYER" "BORDER")
(vl-cmdf ".layer" "m" "BORDER" "C" "251" "" "P" "N" "" "")
)
(setvar "TILEMODE" 0); be sure that you start in a layout
(command ".mview" (getpoint "\nSelect rectangle of viewport...")(getcorner "to..." (getvar "LASTPOINT")))
(vl-cmdf ".chprop" "L" "" "c" "251" "")
(vl-cmdf ".mspace")
(vl-cmdf ".zoom" "O" "L" "")
(vl-cmdf ".zoom" "S" ".5XP")
(vl-cmdf ".pspace")
(vl-cmdf ".layerp")
(princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: autolisp exercise
« Reply #10 on: January 09, 2006, 04:20:55 PM »
And what happens when the layer exist & is frozen? :evil:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: autolisp exercise
« Reply #11 on: January 09, 2006, 04:27:34 PM »
partypooper !


 :-P
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

deegeecees

  • Guest
Re: autolisp exercise
« Reply #12 on: January 09, 2006, 04:31:13 PM »
Code: [Select]
(if (= (logand 1 (cdr (assoc 70 ts))) 1)
(thawthething)
)

 :-)

ELOQUINTET

  • Guest
Re: autolisp exercise
« Reply #13 on: January 09, 2006, 04:35:04 PM »
o god here we go leave it to cab to throw a monkey wrench into the bicycle tire.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: autolisp exercise
« Reply #14 on: January 09, 2006, 04:47:18 PM »
I was thinking more like this: 8-)
Code: [Select]
(defun c:foo (/ lyr p1 p2)
  (setq lyr "BORDER")
  (if (tblsearch "LAYER" lyr)
    (vl-cmdf "._Layer" "_Thaw" lyr "_On" lyr "_UnLock" lyr "_Set" lyr "")
    (vl-cmdf ".layer" "m" lyr "C" "251" "" "P" "N" "" "")
  )
  (setvar "TILEMODE" 0) ; be sure that you start in a layout
  (if (and
        (setq p1 (getpoint "\nSelect rectangle of viewport..."))
        (setq p2 (getcorner p1 "to..."))
      )
    (progn
      (vl-cmdf ".mview" p1 p2)
      (vl-cmdf ".chprop" "L" "" "c" "251" "")
      (vl-cmdf ".mspace")
      (vl-cmdf ".zoom" "O" "L" "")
      (vl-cmdf ".zoom" "S" ".5XP")
      (vl-cmdf ".pspace")
      (vl-cmdf ".layerp")
    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.