Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Automatic Centerline LISP

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Eugengutol
2220 Views, 3 Replies

Automatic Centerline LISP

Hi all !

Recently I got several drawings and need to modify them, so I created a rough but working lisp for changing lines, but I want to make an lisp that would change the lines inside the circles from 0 to Center and linetype to ByLayer. Here's my code, but it doesen't make the assoc function.

 

(defun C:caxis ()
  (setq axis (ssget "X" '((8 . "0") (0 . "Circle"))))
  (setq wtf (car axis))
  (setq coord (cdr (assoc 10 (entget wtf))))
  (Setq lngth (sslength axis))
  (repeat lngth
    (setq s1 (car coord))
    (setq s2 (cdr coord))
    (setq x1 (- 1 s1))
    (setq x2 (- 1 s2))
    (setq x3 (+ 1 s1))
    (setq x4 (+ 1 s2))
    (setq x5 (ssget "_C" '(x1 x2) '(x3 x4) ))
    (command ".chprop" x5 "" "LA" "Center" "LT" "ByLayer" "")
     )
)

 

I can't really understand the assoc function, maybe it's impossible to make using it because it's has many enteties to analyse ?

Thanks in advance

Eugene.

3 REPLIES 3
Message 2 of 4
Kent1Cooper
in reply to: Eugengutol

You appear to be confusing the nature of what is returned by (ssget) with what is returned by (entsel).  From (entsel), you can get the entity name of the selected object with (car) [the first element in a list of an entity and the selection point], but from (ssget), you need to use (ssname) to get an entity out of it.

 

Try something like this kind-of minimal adjustment [untested]:

 

(defun C:caxis (/ axis n cir coord s1 s2 x1 x2 x3 x4 x5); localize variables
  (setq axis (ssget "X" '((8 . "0") (0 . "Circle")))); all Circles on Layer 0
  (repeat (setq n (sslength axis)); number of Circles found

    (setq

      cir (ssname axis (setq n (1- n))); start with last one, count forward one each time through

      coord (cdr (assoc 10 (entget cir)))

      s1 (car coord)
      s2 (cdr coord)
      x1 (- 1 s1)
      x2 (- 1 s2)
      x3 (+ 1 s1)
      x4 (+ 1 s2)
      x5 (ssget "_C" '(x1 x2) '(x3 x4))

    ); setq
    (command ".chprop" x5 "" "LA" "Center" "LT" "ByLayer" "")
  ); repeat
); defun

 

But that can be shortcutted considerably, with far fewer variables:

 

(defun C:caxis (/ cirss n cir ctr ctrents); localize variables
  (setq cirss (ssget "X" '((8 . "0") (0 . "Circle")))); all Circles on Layer 0
  (repeat (setq n (sslength cirss)); number of Circles found

    (setq

      cir (ssname cirss (setq n (1- n))); start with last one, count forward one each time through

      ctr (cdr (assoc 10 (entget cir)))

      ctrents (ssget "_C" (mapcar '- ctr '(1 1 0)) (mapcar '+ ctr '(1 1 0)))

    ); setq
    (command ".chprop" ctrents "" "LA" "Center" "LT" "ByLayer" "")
  ); repeat
); defun

 

Or if what you're after are always things such as center-Lines that do pass precisely through the center of the Circle, you can make a zero-size crossing window:

....

      ctrents (ssget "_C" ctr ctr)

....

That has the advantage that it's not limited to working as expected with only Circles with a radius larger than the square root of 2.  In the case of Circles that size or smaller, the original approach will also change the properties of the Circle itself, and possibly other things you don't want, although that can be mitigated at least somewhat by object-type filtering in (ssget).

 

You might also consider putting some (if) tests in there about whether it found any Circles, or anything going through the middle of them, before proceeding, because it will run into problems if it tries to work with nil as a selection set.

Kent Cooper, AIA
Message 3 of 4
Eugengutol
in reply to: Kent1Cooper

I'm new to the LISP and knew that one of (entget) or (assoc) aren't used properly, but didn't knew the alternatives.

Thanks for help, Kent !

Message 4 of 4
Kent1Cooper
in reply to: Eugengutol


@Eugengutol wrote:

I'm new to the LISP and knew that one of (entget) or (assoc) aren't used properly, but didn't knew the alternatives.

Thanks for help, Kent !


You're welcome.  You really weren't "improper" in the use of those two functions in particular, as far as I could see, but rather the problem was with the getting of entities out of a selection set.  It's always informative to read up about Lisp functions in Help, where you may well learn other things about them that you'll have a use for another time.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost