• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Active Member
    Posts: 6
    Registered: ‎01-03-2013
    Accepted Solution

    Line from origin to object centers

    243 Views, 12 Replies
    01-03-2013 07:43 AM

    Does anyone know of a LISP routine which will draw lines from the center/insertion point of multiple objects to 0,0,0 ? 

    Please use plain text.
    *Expert Elite*
    Posts: 2,066
    Registered: ‎11-24-2009

    Re: Line from origin to object centers

    01-03-2013 09:24 AM in reply to: greenj1

    greenj1 wrote:

    Does anyone know of a LISP routine which will draw lines from the center/insertion point of multiple objects to 0,0,0 ? 


    May i ask as to whats the purpose of this exercise? just curious is all :smileyhappy:

     

     

    Please use plain text.
    Active Member
    Posts: 6
    Registered: ‎01-03-2013

    Re: Line from origin to object centers

    01-03-2013 09:30 AM in reply to: pbejse

    I have a number of objects surrounding a sphere (thousands) which I would like to create lines from to the center of the sphere (co-ords 0,0,0) and then sweep the lines to create cylinders which I will boolean from the sphere.

     

    Hope that makes sense. Any suggestions ?

     

    Please use plain text.
    *Expert Elite*
    Posts: 1,216
    Registered: ‎12-17-2004

    Re: Line from origin to object centers

    01-03-2013 09:56 AM in reply to: greenj1

    greenj1, wrote:
    I have a number of objects surrounding a sphere (thousands) which I would like to create lines from to the center of the sphere
    (co-ords 0,0,0) and then sweep the lines to create cylinders which I will boolean from the sphere.
    ...

     

    Objects are circles?

     

    Henrique

    Please use plain text.
    Valued Contributor
    smaher12
    Posts: 75
    Registered: ‎11-20-2011

    Re: Line from origin to object centers

    01-03-2013 10:27 AM in reply to: hmsilva

    Here is my quick and dirty version of it.

     

    (defun c:test (/ esel cp)
      (setq esel (entsel "\nSelect circle: ")
               cp (cdr (assoc 10 (entget (car esel))))
      )
      (command "line" cp "0,0,0" "")
    (princ)
    )

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,085
    Registered: ‎09-13-2004

    Re: Line from origin to object centers

    01-03-2013 01:09 PM in reply to: greenj1

    greenj1 wrote:

    I have a number of objects surrounding a sphere (thousands) which I would like to create lines from to the center of the sphere (co-ords 0,0,0) and then sweep the lines to create cylinders which I will boolean from the sphere.

    ....


    Based on these assumptions:

    1.  The objects could be of multiple types but all with insertion or insertion-like points [below assumes Circles, Points, and Blocks, but you could include Text/Mtext or some other things, and/or remove one or more types];

    2.  They might be in various orientations/coordinate systems [since they surround a sphere];

    3.  You can select them collectively somehow [via window(s) or something], and want to do that rather than pick one at a time;

    4.  You want the Lines on the current Layer;

    then the following seems to do the Lines portion of what I think you're asking, in limited testing:

     

    (setq ss (ssget '((0 . "CIRCLE,POINT,INSERT"))))
    (repeat (sslength ss)
      (setq ent (ssname ss 0))
      (entmake
        (list
          '(0 . "LINE")
          (cons 10 (trans (cdr (assoc 10 (entget ent))) ent 0))

            ;;; (trans) needed for Circles/Blocks when not in WCS
          '(11 0.0 0.0 0.0)
        ); list
      ); entmake
      (ssdel ent ss)
    ); repeat

    Kent Cooper
    Please use plain text.
    Active Member
    Posts: 6
    Registered: ‎01-03-2013

    Re: Line from origin to object centers

    01-04-2013 01:38 AM in reply to: Kent1Cooper

    Kent you are the man ! Perfect.

     

    One last question. Would it be possible for the lines to go to 0,0 but stay relative to their z co-ordinates ?

    I may need to keep the booleans horizontal for a cleaner print (I am 3D printing this model) as the resolution in the Z is far higher than x,y.

     

    Many thanks for your help :smileyhappy:

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,085
    Registered: ‎09-13-2004

    Re: Line from origin to object centers

    01-04-2013 05:47 AM in reply to: greenj1

    greenj1 wrote:

    .... Would it be possible for the lines to go to 0,0 but stay relative to their z co-ordinates ?

    ....


    If I understand what you're asking correctly [run Lines from the object point to 0,0 in XY but with both Line ends at the Z coordinate of the object point, in the WCS], this does that:

     

    (setq ss (ssget '((0 . "CIRCLE,POINT,INSERT"))))
    (repeat (sslength ss)
      (setq
        ent (ssname ss 0)
        dxf10 (cons 10 (trans (cdr (assoc 10 (entget ent))) ent 0)); object point, in WCS
          ;;; (trans) needed for Circles/Blocks when not in WCS
      ); setq
      (entmake
        (list
          '(0 . "LINE")
          dxf10
          (list 11 0.0 0.0 (cadddr dxf10)); use Z coordinate of object point
        ); list
      ); entmake
      (ssdel ent ss)
    ); repeat

    Kent Cooper
    Please use plain text.
    Mentor
    Posts: 768
    Registered: ‎12-26-2005

    Re: Line from origin to object centers

    01-04-2013 06:02 AM in reply to: greenj1

    Try a mod of Kent's, and, note that circles with a x,y of 0,0 make the '0 length' LINEs:

     (defun KC_liner ( / ss rq p00 cp ncp )
      (setq p00 '(11 0.0 0.0 0.0)   rq 0
            ss (ssget "x" '((0 . "CIRCLE,POINT,INSERT")))

      ' remove the "X"  to manually select the circle entities
      (repeat (sslength ss)
       (setq ent (ssname ss 0)  rq (1+ rq)
             ; (trans) needed for Circles/Blocks when not in WCS       
             cp (trans (cdr (assoc 10 (entget ent))) ent 0)
             ncp (list (car cp) (cadr cp) 0.0) )
         (entmake (list '(0 . "LINE") (cons 10 ncp) p00 ) ); entmake
         (ssdel ent ss)
         ;;(p_"rq")(W_"  1")
      ); repeat
     rq )

    S
    Please use plain text.
    Active Member
    Posts: 6
    Registered: ‎01-03-2013

    Re: Line from origin to object centers

    01-04-2013 11:31 AM in reply to: greenj1

    Kent once again thankyou, this works perfectly on the circles I have tested it on.

    However my circles have to be converted into 3D polylines. The lisp does not seem to work on them !

    I assumed they would have an inserition point or centre and it would work the same way.

    Any suggestions ?

    Please use plain text.