Author Topic: autolisp exercise  (Read 8670 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: autolisp exercise
« Reply #15 on: January 09, 2006, 07:40:39 PM »
This is wordy due to my non concise coding style and inline comments, but hopefully Dan will find it illuminating ...

Code: [Select]
(defun c:foo ( / layername layerobj vportobj delta acadobj docobj )

    ;;
    ;;  make / get the border layer
    ;;

    (setq layerobj
        (vla-add
            (vla-get-layers
                (setq docobj
                    (vla-get-activedocument
                        (setq acadobj
                            (vlax-get-acad-object)
                        )
                    )
                )
            )
            (setq layername "Border")
        )
    )

    ;;
    ;;  set the layer's properties as we see fit
    ;;

    (foreach propertypair

       '(
            (Plottable . :vlax-false)
            (Freeze    . :vlax-false)
            (LayerOn   . :vlax-true)
            (Lock      . :vlax-false)
            (Color     . 251)
        )

        (vlax-put-property
            layerobj
            (car propertypair)
            (cdr propertypair)
        )

    )

    ;;
    ;;  switch to paperspace
    ;;

    (vla-put-activespace docobj 0)

    ;;
    ;;  switch to pspace
    ;;

    (vla-put-mspace docobj :vlax-false)

    ;;
    ;;  get the coords for the vport
    ;;

    (initget 1)
    (setq p1 (getpoint "\nSelect the first corner of the vport: "))

    (initget 1)
    (setq p2 (getcorner p1 "Now the other corner: "))

    ;;
    ;;  make the viewport
    ;;

    (setq vportobj
        (vla-addpviewport
            (vla-get-paperspace docobj)
            (vlax-3d-point
                (mapcar
                   '(lambda (i) (/ i 2.0))
                    (mapcar '+ p1 p2)
                )
            )
            (car
                (setq delta
                    (mapcar
                       '(lambda (a b) (abs (- a b)))
                        p1
                        p2
                    )
                )
            )
            (cadr delta)
        )
    )

    ;;
    ;;  change the vport's layer
    ;;

    (vla-put-layer vportobj layername)

    ;;
    ;;  make sure the vport is on
    ;;

    (vla-display vportobj :vlax-true)

    ;;
    ;;  switch to mspace
    ;;

    (vla-put-mspace docobj :vlax-true)

    ;;
    ;;  zoom extents to center the view
    ;;

    (vla-zoomextents acadobj)

    ;;
    ;;  now zoom relative to paperspace
    ;;

    (vla-zoomscaled acadobj 0.5 acZoomScaledRelativePSpace)

    ;;
    ;;  change back to pspace
    ;;

    (vla-put-mspace docobj :vlax-false)

    ;;
    ;;  shhhh
    ;;

    (princ)

)
« Last Edit: January 09, 2006, 11:24:20 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: autolisp exercise
« Reply #16 on: January 09, 2006, 07:58:37 PM »
Your code makes me smile. 8-)
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 #17 on: January 09, 2006, 09:10:18 PM »
Your code makes me smile. 8-)

Makes me feel that all is well in the world, and that there is hope for mankind.
 :kewl:

when contemplating something so rational, how can it be otherwise.
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: autolisp exercise
« Reply #18 on: January 09, 2006, 09:14:57 PM »
.. except for the next to last comment :-)
Quote
    ;;
    ;;  change back to pspace
    ;;
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: autolisp exercise
« Reply #19 on: January 09, 2006, 09:53:43 PM »
CAB -- your comments make me smile. :)

Kerry, I dunno, I (failthfully) took my stupid pills today so yourlast  comment just confuses me.  :|

(But your first one is nice).

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: autolisp exercise
« Reply #20 on: January 09, 2006, 10:11:40 PM »
I took a double dose of my obtuse pill Michael .. you forgot the layer;P;  reading my comment now, it seems that I'm querying the pspace ..


thats my story, and I'm sticking with it   :lol:


added: You left that for Dan, right ?
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: autolisp exercise
« Reply #21 on: January 09, 2006, 10:18:40 PM »
I took a double dose of my obtuse pill Michael .. you forgot the layer;P;  reading my comment now, it seems that I'm querying the pspace ..


thats my story, and I'm sticking with it   :lol:


added: You left that for Dan, right ?

There's no need -- I don't change the active layer.

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: autolisp exercise
« Reply #22 on: January 09, 2006, 10:26:26 PM »
 :oops:
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: autolisp exercise
« Reply #23 on: January 09, 2006, 10:32:13 PM »
Man I've missed this place.

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

LE

  • Guest
Re: autolisp exercise
« Reply #24 on: January 09, 2006, 10:34:00 PM »
:oops:

What type of job.... the scoreboard does ?  it is only for AutoCAD 2006 ? :lol:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: autolisp exercise
« Reply #25 on: January 09, 2006, 10:36:56 PM »
What type of job.... the scoreboard does ?  it is only for AutoCAD 2006 ? :lol:

I assume you mean the piccy Luis ? That's ObjectDCL ..
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.

LE

  • Guest
Re: autolisp exercise
« Reply #26 on: January 09, 2006, 11:07:48 PM »
Oops.... I do not know what I was saying.....  :ugly:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: autolisp exercise
« Reply #27 on: January 09, 2006, 11:13:17 PM »
heh, that's my speech :-)
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.

ELOQUINTET

  • Guest
Re: autolisp exercise
« Reply #28 on: January 10, 2006, 12:20:20 PM »
wow you guys have been chattin away in here. i'm so happy someone finally responded to one of my posts. i'll take a hard look at cab's and mps code thanks for your help guys.