Change the diameter of all circles on two different layers.

Change the diameter of all circles on two different layers.

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

Change the diameter of all circles on two different layers.

Anonymous
Not applicable
Hello Everyone!

I am trying to find a routine that will change circles located on 2 different layers to a specific diameter (3.025) .Some of the circles are in blocks.

Any assistance is greatly appreciated.

Xi
0 Likes
Accepted solutions (1)
1,545 Views
13 Replies
Replies (13)
Message 2 of 14

Ranjit_Singh
Advisor
Advisor
Accepted solution

@Anonymous wrote:
Hello Everyone!

I am trying to find a routine that will change circles located on 2 different layers to a specific diameter (3.025) .Some of the circles are in blocks [I assume that we are targeting the blocks that are on the specified layers; in my case Layer1 and Layer2]

Any assistance is greatly appreciated.

Xi


Try below for example. Note that I am using Layer1 and Layer2 as example layer names. Replace them with your layer names.

(defun c:somefunc  (/ ent entdata)
 (mapcar '(lambda (x)
           (cond ((= "CIRCLE" (cdr (assoc 0 (setq entdata (entget x)))))
                  (setq entdata (entget x))
                  (entmod (subst (cons 40 (/ 3.025 2)) (assoc 40 entdata) entdata)))
                 (t
                  (setq ent (cdr (assoc -2 (tblsearch "block" (cdr (assoc 2 (entget x)))))))
                  (while ent
                   (and (= "CIRCLE" (cdr (assoc 0 (setq entdata (entget ent)))))
                        (entmod (subst (cons 40 (/ 3.025 2)) (assoc 40 entdata) entdata)))
		   (setq ent (entnext ent))))))
         (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "CIRCLE,INSERT") (8 . "Layer1,Layer2")))))) ; change Layer1 and Layer2 to your layer names
 (vla-regen (vla-get-activedocument (vlax-get-acad-object)) 1)
 (princ))
 (vl-load-com)

 

Message 3 of 14

Anonymous
Not applicable

Thank you Ranjit !

 

Works great. I finally had a change to use it this morning.

0 Likes
Message 4 of 14

Anonymous
Not applicable

I tried it on circles contained within a block.  This is the error that I am getting.

 

 

Error: bad argument type: lselsetp nil
Error Resetting Enviroment

0 Likes
Message 5 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

I tried it on circles contained within a block.  This is the error that I am getting.

 

Error: bad argument type: lselsetp nil

....


I believe that could happen if you have Circles that are on one of those Layers but are inside Blocks that are not Inserted on one of those Layers.  The (ssget) function will not see them.  If that's the case, you would have to adjust the code to find Circles on those Layers and all Blocks, and then in stepping through the entities in the Blocks, check for both whether one is a Circle and whether it's on one of those Layers.

Kent Cooper, AIA
0 Likes
Message 6 of 14

Ranjit_Singh
Advisor
Advisor

Please post a  drawing. I can take a guess, but it would be better to see what your blocks looks like and what properties the circle has. Note that I had mentioned in post 2 that the code only targets blocks that are on layers 1 and 2. So my guess is the blocks in subject drawing are on other layers. But post a drawing so I can confirm before revising the code.

0 Likes
Message 7 of 14

Anonymous
Not applicable

You are correct sir.  By default, all of our blocks are on the 0 layer.  My test drawing was just a bunch of blocked circles (layer1 & layer2) on the zero layer.  

 

I misread your post.

0 Likes
Message 8 of 14

Ranjit_Singh
Advisor
Advisor

OK. Try below.

(defun c:somefunc  (/ ent entdata)
 (mapcar '(lambda (x)
           (cond ((= "CIRCLE" (cdr (assoc 0 (setq entdata (entget x)))))
                  (setq entdata (entget x))
                  (entmod (subst (cons 40 (/ 3.025 2)) (assoc 40 entdata) entdata)))
                 (t
                  (setq ent (cdr (assoc -2 (tblsearch "block" (cdr (assoc 2 (entget x)))))))
                  (while ent
                   (and (= "CIRCLE" (cdr (assoc 0 (setq entdata (entget ent)))))
                        (wcmatch (cdr (assoc 8 entdata)) "Layer1,Layer2")
                        (entmod (subst (cons 40 (/ 3.025 2)) (assoc 40 entdata) entdata)))
                   (setq ent (entnext ent))))))
          (mapcar 'cadr (ssnamex (ssget "_x" '((-4 . "<or") (-4 . "<and")  (0 . "circle") (8 . "Layer1,Layer2") (-4 . "and>")  (-4 . "<and") (0 . "insert") (8 . "0")  (-4 . "and>") (-4 . "or>")))))) ; change Layer1 and Layer2 to your layer names
 (vla-regen (vla-get-activedocument (vlax-get-acad-object)) 1)
 (princ))
(vl-load-com)
0 Likes
Message 9 of 14

Anonymous
Not applicable

I tried it out. I do not get an error but the circles within blocks do not change.  All other circles do indeed change to the referenced diameter.

0 Likes
Message 10 of 14

Ranjit_Singh
Advisor
Advisor

As mentioned before please upload a drawing with the subject blocks. Maybe a small portion if you cannot upload the whole drawing. I need to see the block definition because I am obviously missing something.

0 Likes
Message 11 of 14

Anonymous
Not applicable
Please see attached.
0 Likes
Message 12 of 14

Ranjit_Singh
Advisor
Advisor

I tested this drawing against post 2 code and it works. I am not sure why it does not work for you. Do a screencast to show exactly what is happening.  See the screencast below that shows that it works.

Message 13 of 14

Anonymous
Not applicable

My PC is getting refreshed today.  I'll download screencast when I get the new one.  It appears to be something on my end as it obviously works perfectly for you. 

 

I will advise when I get setup.

0 Likes
Message 14 of 14

Anonymous
Not applicable

Attached is the screencast of what is happening.  I am using the second code that was posted.

0 Likes