Jump to content

Recommended Posts

Posted

Thank you David, I very much appreciate your compliments.

 

It's probably not the easiest code for a beginner to start learning from, but I admire your enthusiasm and would encourage you to pursue your learning of AutoLISP.

 

Good luck!

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • dortega4269

    13

  • Lee Mac

    7

  • Tharwat

    3

  • satishrajdev

    2

Posted
"...It's probably not the easiest code for a beginner to start learning from..."

 

Lee Mac you were so very right, this code was not by any means easy to decipher. After reading through Afralisp for several hours and reading through your code, I now have a better understanding of what you are doing as far as creating lists and calling them up, however, trying to figure out what you are doing with each line is another story. I will enjoy and appreciate what you have provided to me and I will keep reading and gaining a better understanding of writing code. Thanks again Lee Mac:thumbsup:

Posted

Lee Mac provided me with an awesome bit of code, but I am unsure of how to alter it. Everything is returning with an error. I have two things I'd like to see it do, but I don't know where to place any code I want to add...

  1. How would I go about making command repeat, as to, click on an object several times and have it rotate 90 degrees each time?
  2. How can I alter this code to make it rotate -90 from 0 (clockwise)?

Posted

  1. How would I go about making command repeat, as to, click on an object several times and have it rotate 90 degrees each time?
  2. How can I alter this code to make it rotate -90 from 0 (clockwise)?

 

Try this David,

([color=BLUE]defun[/color] c:r90 ( [color=BLUE]/[/color] a e f k x )
   
   ([color=BLUE]setq[/color] a ([color=BLUE]/[/color] [color=BLUE]pi[/color] 2.0)) [color=GREEN];; Rotation Angle[/color]
   
   ([color=BLUE]initget[/color] [color=MAROON]"X Y Z"[/color])
   ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"Z"[/color] ([color=BLUE]setq[/color] k ([color=BLUE]getkword[/color] [color=MAROON]"\nChoose Block Rotation Axis [X/Y/Z] <X>: "[/color])))
       ([color=BLUE]setq[/color] f
           ([color=BLUE]lambda[/color] ( l [color=BLUE]/[/color] r )
               ([color=BLUE]setq[/color] r ([color=BLUE]assoc[/color] 50 l))
               ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 50 ([color=BLUE]+[/color] a ([color=BLUE]cdr[/color] r))) r l))
           )
       )
       ([color=BLUE]setq[/color] f
           ([color=BLUE]lambda[/color] ( l [color=BLUE]/[/color] e r )
               ([color=BLUE]setq[/color] e ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] -1 l))
                     r ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 50 l))
               )
               ([color=BLUE]vlax-invoke[/color] ([color=BLUE]vlax-ename->vla-object[/color] e) 'rotate3d
                   ([color=BLUE]trans[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 10 l)) e 0)
                   ([color=BLUE]trans[/color]
                       ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 10 l))
                           ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"Y"[/color] k)
                               ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]sin[/color] r)) ([color=BLUE]cos[/color] r) 0.0)
                               ([color=BLUE]list[/color] ([color=BLUE]cos[/color] r) ([color=BLUE]sin[/color] r) 0.0)
                           )
                       )
                       e 0
                   )
                   a
               )
           )
       )
   )
   ([color=BLUE]while[/color]
       ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] e ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect Block <Exit>: "[/color])))
           ([color=BLUE]cond[/color]
               (   ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno))
                   ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color])
               )
               (   ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] e))
                   ([color=BLUE]setq[/color] x ([color=BLUE]entget[/color] e))
                   ([color=BLUE]cond[/color]
                       (   ([color=BLUE]=[/color] 4 ([color=BLUE]logand[/color] 4 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 70 ([color=BLUE]tblsearch[/color] [color=MAROON]"layer"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 8 x)))))))
                           ([color=BLUE]princ[/color] [color=MAROON]"\nObject is on locked layer."[/color])
                       )
                       (   ([color=BLUE]=[/color] [color=MAROON]"INSERT"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 x)))
                           (f x) [color=BLUE]t[/color]
                       )
                       (   ([color=BLUE]princ[/color] [color=MAROON]"\nSelected object is not a block."[/color]))
                   )
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

A clockwise rotation would require an additional prompt, so I suggest it may be quicker to simply click the object 3 times...

Posted

Alternatively, this may be more suitable:

([color=BLUE]defun[/color] c:rb ( [color=BLUE]/[/color] a e f k r x )
   
   ([color=BLUE]setq[/color] a ([color=BLUE]/[/color] [color=BLUE]pi[/color] 2.0)) [color=GREEN];; Default Rotation Angle[/color]
   
   ([color=BLUE]initget[/color] [color=MAROON]"X Y Z"[/color])
   ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"Z"[/color] ([color=BLUE]setq[/color] k ([color=BLUE]getkword[/color] [color=MAROON]"\nChoose Block Rotation Axis [X/Y/Z] <X>: "[/color])))
       ([color=BLUE]setq[/color] f
           ([color=BLUE]lambda[/color] ( l [color=BLUE]/[/color] r )
               ([color=BLUE]setq[/color] r ([color=BLUE]assoc[/color] 50 l))
               ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 50 ([color=BLUE]+[/color] a ([color=BLUE]cdr[/color] r))) r l))
           )
       )
       ([color=BLUE]setq[/color] f
           ([color=BLUE]lambda[/color] ( l [color=BLUE]/[/color] e r )
               ([color=BLUE]setq[/color] e ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] -1 l))
                     r ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 50 l))
               )
               ([color=BLUE]vlax-invoke[/color] ([color=BLUE]vlax-ename->vla-object[/color] e) 'rotate3d
                   ([color=BLUE]trans[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 10 l)) e 0)
                   ([color=BLUE]trans[/color]
                       ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 10 l))
                           ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"Y"[/color] k)
                               ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]sin[/color] r)) ([color=BLUE]cos[/color] r) 0.0)
                               ([color=BLUE]list[/color] ([color=BLUE]cos[/color] r) ([color=BLUE]sin[/color] r) 0.0)
                           )
                       )
                       e 0
                   )
                   a
               )
           )
       )
   )
   ([color=BLUE]while[/color]
       ([color=BLUE]progn[/color]
           ([color=BLUE]setvar[/color] 'errno 0)
           ([color=BLUE]initget[/color] [color=MAROON]"Rotation"[/color])
           ([color=BLUE]setq[/color] e ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect Block [Rotation] <Exit>: "[/color]))
           ([color=BLUE]cond[/color]
               (   ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno))
                   ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color])
               )
               (   ([color=BLUE]=[/color] '[color=BLUE]list[/color] ([color=BLUE]type[/color] e))
                   ([color=BLUE]setq[/color] x ([color=BLUE]entget[/color] ([color=BLUE]car[/color] e)))
                   ([color=BLUE]cond[/color]
                       (   ([color=BLUE]=[/color] 4 ([color=BLUE]logand[/color] 4 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 70 ([color=BLUE]tblsearch[/color] [color=MAROON]"layer"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 8 x)))))))
                           ([color=BLUE]princ[/color] [color=MAROON]"\nObject is on locked layer."[/color])
                       )
                       (   ([color=BLUE]=[/color] [color=MAROON]"INSERT"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 x)))
                           (f x) [color=BLUE]t[/color]
                       )
                       (   ([color=BLUE]princ[/color] [color=MAROON]"\nSelected object is not a block."[/color]))
                   )
               )
               (   ([color=BLUE]=[/color] [color=MAROON]"Rotation"[/color] e)
                   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] r ([color=BLUE]getangle[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nSpecify Rotation Angle <"[/color] ([color=BLUE]angtos[/color] a) [color=MAROON]">: "[/color])))
                       ([color=BLUE]setq[/color] a r)
                       [color=BLUE]t[/color]
                   )
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Posted

Both bits of code work great, I went with the later based on your comments (more suitable). This makes the process of rotating a block faster!:thumbsup: Thanks again Lee Mac.:notworthy:

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