Simple Program to Update Object Properties

Simple Program to Update Object Properties

ben.leistiko
Participant Participant
1,326 Views
6 Replies
Message 1 of 7

Simple Program to Update Object Properties

ben.leistiko
Participant
Participant

Hi,

I am trying to create a simple script that will update the diameter of all the circles on a specific layer and later I want it to change the style of all MText objects.  Here is what I have so far:

(setq sel1 (ssget "X" '((0 . "CIRCLE")(8 . "Text"))))
(setpropertyvalue (entlast) "radius" 5)

Here are the results of that script:

Command: '_script
Command: (setq sel1 (ssget "X" '((0 . "CIRCLE")(8 . "Text"))))
<Selection set: 1be6>
Command: (setpropertyvalue (entlast) "radius" 5)
nil

I also tried this:

(setq sel1 (ssget "X" '((0 . "CIRCLE")(8 . "Text"))))
(setpropertyvalue sel1 "radius" 5)

and got this result:

Command: '_script
Command: (setq sel1 (ssget "X" '((0 . "CIRCLE")(8 . "Text"))))
<Selection set: 1beb>
Command: (setpropertyvalue sel1 "radius" 5)
; error: ADS request error

In a document with a "Text" layer that has circles on it nothing happens.  Does anyone know why this is?  Also does anyone know what the ADS error is and why I got it?

 

Finally, when i am actually using this script some files have a Text layer while others have a TEXT layer, will the capitalization make a difference?

 

Thanks, 

--Ben (AutoCAD mechanical 2013)

0 Likes
Accepted solutions (2)
1,327 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

 

(defun c:RadiusTo5 (/ ss i)
  (if (setq ss (ssget "X" '((0 . "CIRCLE")(8 . "Text"))))
    (repeat (setq i (sslength ss))
      (setpropertyvalue (ssname ss (setq i (1- i))) "Radius" 5)))
  (princ)
  )

 

Selection set (ss) collects many entities, but (setpropertyvalue) accepts just one. You need to iterate thru the ss somehow. HERE you have many ways how to do that. I've used 2a method - reversed repeat. It's probably most popular method around here. The most straight forward.

 

Message 3 of 7

ben.leistiko
Participant
Participant

Thank you so much, this worked very well.  I attempted to apply this same method to text object and have been unable to get anything to work.  Here is what I have:

style
ARIAL
arial
5
1
0
no
no
(vl-load-com)
(if (setq ss (ssget "X" '((0 . "MTEXT")(8 . "TEXT"))))
(repeat (setq i (sslength ss))
(vla-put-stylename (vlax-ename->vla-object (ssname ss (setq i (1- i)))) "ARIAL")

This properly created the style but did not do anything to change the style of MTEXT objects.  Can anyone point out what I am doing wrong?

 

Thanks so much,

Ben

0 Likes
Message 4 of 7

dlanorh
Advisor
Advisor
Accepted solution
(defun c:Style2MT (/ ss i)
  (if (setq ss (ssget "X" '((0 . "MTEXT")(8 . "Text"))))
    (repeat (setq i (sslength ss))
      (vlax-put-property (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'stylename "ARIAL")
    )
  )
  (princ)
)

This should work, provided the text style hasn't been overridden in the textstring, a "feature" of MTEXT

I am not one of the robots you're looking for

Message 5 of 7

ВeekeeCZ
Consultant
Consultant

@ben.leistiko wrote:

...

...
(vl-load-com)
(if (setq ss (ssget "X" '((0 . "MTEXT")(8 . "TEXT"))))
(repeat (setq i (sslength ss))
(vla-put-stylename (vlax-ename->vla-object (ssname ss (setq i (1- i)))) "ARIAL")))

....


 

This was is also possible.. just need to maintain parenthesis.

0 Likes
Message 6 of 7

Sea-Haven
Mentor
Mentor

Use Notepad++ it has built in lisp checking and its free.

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@ben.leistiko wrote:

.... I am trying to create a simple script that will update the diameter of all the circles on a specific layer and later I want it to change the style of all MText objects.  ....


 

QSELECT can do both of those for you pretty quickly, without any code.  And it lets you apply any  radius [to Circles] or text Style [to Mtext] [and/or any other Properties the selection has in common]  in the Properties palette to the resulting selection -- you're not limited to one explicitly built into the code.

 

QSELECTCircleTextLayer.PNG

 

[I confess to being curious as to why one would put Circles on a Text Layer....]

Kent Cooper, AIA
0 Likes