Append object data table record for all objects in selection set (Issue)

Append object data table record for all objects in selection set (Issue)

Anonymous
Not applicable
1,718 Views
6 Replies
Message 1 of 7

Append object data table record for all objects in selection set (Issue)

Anonymous
Not applicable

I think I'm close as I get no errors, but the following lisp routine is not making the change to the object data set as expected.  The intent is to add default text string into the object data field for all selected objects (in this case by layer name).  The selection set seems correct.  Any help is appreciated:

 

(defun c:addodtext( / i s )
    (if (setq ss (ssget "_X" '((8 . "V-STRM-PIPE"))))
        (ade_odsetfield ss "GRAVITY PIPES" "P_CLASS" 0 "Storm Drainage")
    )
    (princ)
)
0 Likes
Accepted solutions (2)
1,719 Views
6 Replies
Replies (6)
Message 2 of 7

CodeDing
Advisor
Advisor
Accepted solution

@Anonymous,

 

I do not remember where I found the attached document (see pg. 241), but it has come in handy many times..

Looks like:

ss - this should be an entity name

"GRAVITY PIPES" - this should not have spaces

(defun c:addodtext( / i s )
    (if (setq ss (ssget "_X" '((8 . "V-STRM-PIPE"))))
        (ade_odsetfield ss "GRAVITY PIPES" "P_CLASS" 0 "Storm Drainage")
    )
    (princ)
)

...if you have multiple items in your selection set, then you will need some kind of loop (untested)...

(repeat (setq cnt (sslength ss))
    (setq e (ssname ss cnt))
    (ade_odsetfield e "GRAVITY_PIPES" "P_CLASS" 0 "STORM_DRAINAGE")
    (setq cnt (1- cnt))
);repeat

...hope this & documentation helps.

 

Best,

~DD

0 Likes
Message 3 of 7

Anonymous
Not applicable

What if I wanted the text string to be a sequential number instead of "Storm Drainage"?   I've poked around and found some complex routines but it seems like it should be simpler.  Apologies I'm both a noob and vet.  I learned all this stuff over 15 years ago and haven't used it since.  

0 Likes
Message 4 of 7

CodeDing
Advisor
Advisor

@Anonymous,

 

Something like...

(repeat (setq cnt (sslength ss))
    (setq e (ssname ss cnt) tmp (- (+ 1 (sslength ss)) cnt))
    (ade_odsetfield e "GRAVITY_PIPES" "P_CLASS" 0 (strcat "STORM_DRAINAGE_" (itoa tmp)))
    (setq cnt (1- cnt))
);repeat

Best,

~DD

 

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

I couldn't get the repeat function to work the way you wrote it, but I did find some older code that I had done and figured it out.  But now I'm still stuck with how to replace the storm drainage string with sequential numbering.  Here's where I left off with it working:

 

(defun c:addodtext( / i s )
  (setq ss1 (ssget "_X" '((8 . "V-STRM-PIPE"))))
	(if (/= ss1 nil)
		(progn
			(setq i (sslength ss1)) (while (not (minusp (setq i (1- i))))
 				(ade_odsetfield (ssname ss1 i) "GRAVITY_PIPES" "P_CLASS" 0 "Storm Drainage")		
 			)
		)	
		(progn (princ))
	)
)
Message 6 of 7

CodeDing
Advisor
Advisor
Accepted solution

I hope this helps clear things up. I cleaned up your code a bit to maybe help jog your memory on those good practices.

(defun c:addodtext( / ss1 i)
(if (setq ss1 (ssget "_X" '((8 . "V-STRM-PIPE"))))
	(repeat (setq i (sslength ss1))
		(setq i (1- i))
		;only keeps number (number starts with 1)
		(ade_odsetfield (ssname ss1 i) "GRAVITY_PIPES" "P_CLASS" 0 (itoa (- (sslength ss1) i)))
	);repeat -> only one function used so no need for progn
);if
(princ);finish quietly since we're not returning anything
);defun

;keeps "Storm_Drainage_" and number (number starts with 1)
;(ade_odsetfield (ssname ss1 i) "GRAVITY_PIPES" "P_CLASS" 0 (strcat "Storm_Drainage_" (itoa (- (sslength ss1) i))))

;keeps "Storm_Drainage_" and number (number starts with length of ss)
;(ade_odsetfield (ssname ss1 i) "GRAVITY_PIPES" "P_CLASS" 0 (strcat "Storm_Drainage_" (itoa (+ 1 i))))

;only keeps number (number starts with length of ss)
;(ade_odsetfield (ssname ss1 i) "GRAVITY_PIPES" "P_CLASS" 0 (itoa (+ 1 i)))

...you can delete the lines outside of the function. I put them there so you can choose how you want to number things.

Best,

~DD

 

0 Likes
Message 7 of 7

Anonymous
Not applicable

Thanks for putting in the notes to clarify the processes and funcitons.  It all is hazy still, but I can follow it now.

0 Likes