+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Forum Newbie dak's Avatar
    Computer Details
    dak's Computer Details
    Operating System:
    ms windows xp sp3
    Discipline
    See details...
    dak's Discipline Details
    Occupation
    pcs commissioning
    Discipline
    See details below.
    Details
    process ctrl
    Using
    AutoCAD 2012
    Join Date
    May 2013
    Location
    St. Petersburg, Russia
    Posts
    3

    Default Make a loop return the result for each time its body is obeyed

    Registered forum members do not see this ad.

    Hi everyone,

    Just trying to pass a list of points to a "pline" command.
    The problem is num of points is initially unknown, though being calculated within a routine.
    The following code (as smth to start with) evolves known num of points.
    Code:
    (defun c:pltest6 ()
    	(setq pts (list '(0 0) '(0 10) '(10 10) '(10 20) '(20 20) '(20 30) '(30 30)))
    	(setq ptqty 7)
    	(setq ptnum 0)
    	(command "pline"
    		(car pts)
    		(pt_retr pts)
    		(pt_retr pts)
    		(pt_retr pts)
    		(pt_retr pts)
    		(pt_retr pts)
    		(pt_retr pts)
    		""
    	)
    )
    (defun pt_retr (lst)
    	(setq ptnum (1+ ptnum))
    	(repeat ptnum
    		(setq lst (cdr lst))
    	)
    	(setq pt (car lst))
    )
    Repeat/foreach don't do, 'cause they return the value of the last iteration..
    Now my Q is,
    is it possible to modify the code above to use loop instead of repeat one and the same line (moreover, unknown number of times ),
    OR some other approach would rather fix the task?

    Thank you in advance,
    Dmitro

  2. #2
    Luminous Being BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    2 x 240GB Samsung EVO SSD (RAID 0)
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Discipline
    Civil
    BlackBox's Discipline Details
    Occupation
    Senior Civil Designer
    Discipline
    Civil
    Details
    Public/Private Land Development, Transportation, and Utilities.
    Using
    Civil 3D 2016
    Join Date
    Nov 2009
    Posts
    5,282

    Default

    Code:
    (defun c:FOO (/ _FOO pts)
    
      (defun _FOO (pts /)
        (command "._pline") (foreach pt pts (command pt)) (command)
      )
    
      (if (setq pts '((0 0)(0 10)(10 10)(10 20)(20 20)(20 30)(30 30)))
        (_FOO pts)
      )
      (princ)
    )
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Sincpac C3D ~ Exchange Apps ~ Autoloader ~ AutoCAD Security

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Example:
    Code:
    (defun c:pline-example ( / lst )
        (setq lst '((0 0) (0 10) (10 10) (10 20) (20 20) (20 30) (30 30)))
        (apply 'command (append '("_.pline") lst '("")))
        (princ)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  4. #4
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Or
    Code:
    (command "_pline")(mapcar 'command pt)(command "_cl")
    to make them closed, of course osmode is set to 0 before
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  5. #5
    Forum Newbie dak's Avatar
    Computer Details
    dak's Computer Details
    Operating System:
    ms windows xp sp3
    Discipline
    See details...
    dak's Discipline Details
    Occupation
    pcs commissioning
    Discipline
    See details below.
    Details
    process ctrl
    Using
    AutoCAD 2012
    Join Date
    May 2013
    Location
    St. Petersburg, Russia
    Posts
    3

    Default

    BlackBox, Lee Mac & fixo,

    Thank you so much.
    I see I need 1,000 x more practice to get accustomed to lisp.
    Sorry if you found my question borring.

    Regards,
    Dmitro

    P.S. Does there exist a Forum/Thread where LISP is compared with another languages?
    E.g. "THAT's C/Pascal/Basic code - and THIS is how we do it in LISP".

  6. #6
    Super Member
    Using
    AutoCAD 2012
    Join Date
    Jun 2012
    Posts
    902

    Default

    Quote Originally Posted by dak View Post
    P.S. Does there exist a Forum/Thread where LISP is compared with another languages?
    E.g. "THAT's C/Pascal/Basic code - and THIS is how we do it in LISP".
    You might ought to ask this in a separate thread. But note that AutoLISP and Visual LISP are not really LISP, but dialects of it intended specifically for AutoCAD. Also, LISP is not the same type of language, so if you want to do it "right", it may be better not to try to think too much in terms of such languages. BTW, interestingly, no one mentioned that while would be a substitute looping function for repeat when stepping through a variable number of items, or when the number is of no importance. Could this be because AutoLISP works differently than the other languages you mention?
    When all you have is a hammer, everything looks like a nail.--

    “Doc, it hurts when I do this.” “Well, don’t do that!”

    “Well, if you don’t know, I’m certainly not going to tell you!”

  7. #7
    Super Member
    Using
    AutoCAD 2012
    Join Date
    Jun 2012
    Posts
    902

    Default

    Quote Originally Posted by fixo View Post
    Or
    Code:
    (command "_pline")(mapcar 'command pt)(command "_cl")
    to make them closed, of course osmode is set to 0 before
    Good point about OSMODE! Why not just apply instead of mapcar?
    Code:
    (command "_pline")(apply 'command pts)(command "")
    Or were you just showing that there is yet another function option?
    When all you have is a hammer, everything looks like a nail.--

    “Doc, it hurts when I do this.” “Well, don’t do that!”

    “Well, if you don’t know, I’m certainly not going to tell you!”

  8. #8
    Luminous Being BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    2 x 240GB Samsung EVO SSD (RAID 0)
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Discipline
    Civil
    BlackBox's Discipline Details
    Occupation
    Senior Civil Designer
    Discipline
    Civil
    Details
    Public/Private Land Development, Transportation, and Utilities.
    Using
    Civil 3D 2016
    Join Date
    Nov 2009
    Posts
    5,282

    Default

    Quote Originally Posted by dak View Post
    P.S. Does there exist a Forum/Thread where LISP is compared with another languages?
    E.g. "THAT's C/Pascal/Basic code - and THIS is how we do it in LISP".
    There is no specific place for that sort of comparison, but it makes logical sense to want to understand how to accomplish similar task in different languages... In terms of AutoCAD, methinks the most common is quickly becoming Visual LISP vs. .NET (predominantly C# from what I see, but also some VB.NET, and F#)... I suspect you might see more VBA now that VBA 7.1 is supported.

    As an aside, only when I was adept at coding LISP did I make the leap into the deep end of the .NET API, teaching myself C# & VB... It is then that I truly realized just how elegant LISP code can be, despite it's performance hit, with it's utter lack of Transactions, DocumentLocks, static Fields, permissions, etc.... It made me appreciate LISP even more than I thought I already had.

    If you really have something in mind that 'here's how I do this in LISP, how can I do the same in .NET?' etc., post a thread in the .NET forum, include your LISP code, and we'll help you out.

    Cheers
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Sincpac C3D ~ Exchange Apps ~ Autoloader ~ AutoCAD Security

  9. #9
    Forum Newbie dak's Avatar
    Computer Details
    dak's Computer Details
    Operating System:
    ms windows xp sp3
    Discipline
    See details...
    dak's Discipline Details
    Occupation
    pcs commissioning
    Discipline
    See details below.
    Details
    process ctrl
    Using
    AutoCAD 2012
    Join Date
    May 2013
    Location
    St. Petersburg, Russia
    Posts
    3

    Default

    neophoible,

    You right this could not of course! ; post #6 is concerned

    My problem was in fact that I had no idea of how I would "screw" loops to the "pline" command. And that was because since you used to code a great deal in some language, you have adopted its specific tricks. In this case I concluded list functions rule (which was not obvious for me when I raised this thread).

    Regards,
    Dmitro

  10. #10
    Super Member
    Using
    AutoCAD 2012
    Join Date
    Jun 2012
    Posts
    902

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by dak View Post
    neophoible,

    You right this could not of course! ; post #6 is concerned

    My problem was in fact that I had no idea of how I would "screw" loops to the "pline" command. And that was because since you used to code a great deal in some language, you have adopted its specific tricks. In this case I concluded list functions rule (which was not obvious for me when I raised this thread).

    Regards,
    Dmitro
    Actually, what was not obvious to me, until I saw someone do it, is that you can split a command up with multiple calls to command. That was a great revelation for me. FWIW, here is a trivial example of how while could be used:
    Code:
    (defun C:Q (/ P)
      (command "_.PLINE")
      (while
        (setq P (getpoint))
        (command P)
      )
      (command "")
    )
    When all you have is a hammer, everything looks like a nail.--

    “Doc, it hurts when I do this.” “Well, don’t do that!”

    “Well, if you don’t know, I’m certainly not going to tell you!”

Similar Threads

  1. Further Creating Solid Body from a Solid Body
    By nicolas in forum Autodesk Inventor
    Replies: 1
    Last Post: 14th Aug 2012, 01:59 pm
  2. Replies: 0
    Last Post: 8th Jul 2011, 08:49 am
  3. Replies: 6
    Last Post: 22nd Feb 2011, 11:27 pm
  4. How to make a existing cad command loop continuously ???
    By MikeP in forum AutoLISP, Visual LISP & DCL
    Replies: 16
    Last Post: 24th Jan 2011, 06:57 pm
  5. Subtracting result
    By boyo in forum AutoCAD 3D Modelling & Rendering
    Replies: 7
    Last Post: 20th Nov 2008, 06:32 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts