modifying lisp to work for multiple circles

modifying lisp to work for multiple circles

Anonymous
Not applicable
1,132 Views
13 Replies
Message 1 of 14

modifying lisp to work for multiple circles

Anonymous
Not applicable

Good Evening 
i found this lisp on the internet that trim inside a circle 
but it works by selecting one circle each time 
i need to select all the circles in the drawing (almost 2200 circle) once and the lisp trimming them all 
thanks in advance 

 

(defun c:ctrim ( / circ_pts lst ang inc tmp seg pt ent
ctrim_err x f_pts svd_os svd_cmd svd_err)

(defun ctrim_err (s)
(if(/= s "Function cancelled")
(princ(strcat "\n\n" s)) )
(setvar "cmdecho" svd_cmd)
(setvar "osmode" svd_os)
(setq *error* svd_err)
)

(defun circ_pts (enm)
(setq lst (entget enm)
ang (* pi 2)
inc (/ ang 64)
tmp '()
seg 65
)
(repeat seg
(setq pt (polar(cdr(assoc 10 lst))ang
(-(cdr(assoc 40 lst))0.01))
ang (+ inc ang)
)
(setq tmp(cons pt tmp))
)
tmp
)


(setq ent (car(entsel "\nSelect circle: "))
svd_err *error*
*error* ctrim_err
svd_os (getvar "osmode")
svd_cmd (getvar "cmdecho")
)
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(if(and ent
(=(cdr(assoc 0(entget ent)))"CIRCLE")
)
(progn
(setq f_pts(circ_pts ent))
(command "trim" ent "" "f") ;run twice in case the same
(foreach x f_pts(command x)) ;object intersects circle twice
(command "" "")
(command "trim" ent "" "f")
(foreach x f_pts(command x))
(command "" "")
(if(setq x(ssget "wp" f_pts))
(command "erase" x "")
)
)
)
(setvar "cmdecho" svd_cmd)
(setvar "osmode" svd_os)
(setq *error* svd_err)
(princ)
)

 


 

0 Likes
1,133 Views
13 Replies
Replies (13)
Message 2 of 14

Kent1Cooper
Consultant
Consultant

The version of that >here< is made to do it with all Circles on a given Layer in the entire drawing.  Will that work for you?

Kent Cooper, AIA
Message 3 of 14

Anonymous
Not applicable

i noticed the code in the comments is that what you referring to?
if that so i cant find the command name that will be used in autocad

0 Likes
Message 4 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

i noticed the code in the comments is that what you referring to?
if that so i cant find the command name that will be used in autocad


It's the CTRIM.lsp code attached to Message 1.  My link was to that Message specifically, not just to the Topic.

 

The command name is always what comes immediately after

 

(defun C:CommandNameHere

 

in this case, CTRIM just like the file name.

Kent Cooper, AIA
0 Likes
Message 5 of 14

marko_ribar
Advisor
Advisor

You can try code posted here :

 

https://www.cadtutor.net/forum/topic/37907-how-trim-many-line-inside-multi-circle-on-one-step/?do=fi... 

 

HTH.

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 6 of 14

Anonymous
Not applicable

i'm sorry if i didn't follow up with you but this code does not have defun c:ctrim

0 Likes
Message 7 of 14

Anonymous
Not applicable

i tried it but for some reason it didn't appear in command bar 

0 Likes
Message 8 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

i'm sorry if i didn't follow up with you but this code does not have defun c:ctrim


Again, I wasn't linking to that thread for the code in Message 5 there, but to Message 1 there specifically, for the code in the file attached there.  See again the first sentence in Message 4 here.

 

But if you want to use the code in Message 5 there, shown in your image, the command name is farther down after some sub-routine definitions, but it's written for Polyline boundaries on a specific Layer, not for Circles that you asked about, as in what I was trying to direct you to.

Kent Cooper, AIA
0 Likes
Message 9 of 14

Anonymous
Not applicable

i downloaded it but it did nothing unfortunately 
sorry for bothering you and thanks for helping   

0 Likes
Message 10 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

i downloaded it but it did nothing unfortunately ....


Did you edit it at all?  As mentioned in my first Reply here, it's written for Circles on a specific Layer.  I doubt you have exactly that Layer name in your drawing, and you put all the desired Circles on it -- edit that for the name of the Layer of the Circles you're looking for.  If you don't want them selected by Layer, other edits can be made to have it ask for User selection, or other approaches.

 

If you've already changed that Layer name, tell us more about what "it did nothing" means.  Did it fail to load?  Did it load but the command name was not recognized?  Did it recognize the command name but nothing happened?  Did something happen, but not what you expected?  Were there any error messages?  Etc., etc., etc.

Kent Cooper, AIA
0 Likes
Message 11 of 14

Anonymous
Not applicable

all my circles are on a layer called (circle)
after i loaded lisp (Ctrim) it was loaded and recognized the name of the command but nothing happened 
this is the drawing I'm working on 
you may notice some of the circles are trimmed but those because I'm currently  trimming manually 

 

0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

That doesn't answer my first question.  Did you change the Layer name in the selection part of the routine?  It's written for Circles on a Layer called "MANHOLE."  Did you change this line:

 

(if (setq ss (ssget "_X" '((0 . "CIRCLE") (8 . "MANHOLE"))))

 

to this, to find your Circles on Layer "circle"?

 

(if (setq ss (ssget "_X" '((0 . "CIRCLE") (8 . "circle"))))

 

[not case-sensitive]

Kent Cooper, AIA
0 Likes
Message 13 of 14

Anonymous
Not applicable

IT WORKED !! 
the name of the layer was the problem 😅😅
Really thanks a lot for being patient 🌹🌹

0 Likes
Message 14 of 14

Sea-Haven
Mentor
Mentor

Just a suggestion for me I tend to look at a more global answers saves the question in this topic "But I have another layer".

 

So I would ask user to select an object to get the layer name.

(setq lay (cdr (assoc 8 (entget (car (entsel "\nPick object for layer"))))))
(if (setq ss (ssget "_X" (list (cons 0 "CIRCLE") (cons 8 lay))))

 

 

0 Likes