TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Shade on March 17, 2008, 01:23:35 PM
-
Does any one have a lisp that will change the object in a field with out changing the other field settings.
I want to be able to quickly make a text with a field in it that tells me an objects property and they copy the text and hook up the field to another object without re-editiing the field.
For example;
Text field A is set to object; linetype of object A and I want to copy the text and set the field to linetype, object B by I picking object B.
I may have to write my own lisp, and I am currently brainstorming and writing pseudo code for it as we speak.
Any help would be appreciated.... :mrgreen:
PS I will post some code when I have something to post. ;-)
-
See if this will help you out. (http://www.theswamp.org/index.php?topic=20446.0)
-
Try the codes
;;; Input obj=ENAME
(Defun x-get-fieldcode (obj / abc)
(if (and vla-fieldcode
(setq obj (vlax-ename->vla-object obj))
(vlax-method-applicable-p obj "FieldCode")
(setq abc (vla-fieldcode obj))
)
(while (vl-string-search "_ObjIdx" abc)
(setq abc (vl-string-subst "_ObjId" "_ObjIdx" abc))
)
)
abc
)
;;; Input obj=ENAME
(Defun x-get-fieldobj (obj / abc pos idx obx)
(setq abc (x-get-fieldcode obj))
(while (wcmatch abc "*(%<\\_ObjId ##########>%)*")
(setq pos (+ 12 (vl-string-search "(%<\\_ObjId " abc))
idx (cons (substr abc pos 10) idx)
abc (substr abc (+ pos 11))
)
)
(foreach pos idx
(setq obx (cons (vlax-vla-object->ename (vla-objectidtoobject
(vla-Get-ActiveDocument (vlax-Get-Acad-Object))
(read pos)
))
obx
)
)
)
obx
)
;;; Input obj=ENAME
;;; Input new=ENAME or ENAME LIST
(Defun x-put-fieldobj(obj new / abc xyz ob nn)
(setq abc (x-get-fieldcode obj)
xyz (x-get-fieldobj obj)
xyz (mapcar 'vlax-ename->vla-object xyz)
xyz (mapcar 'vla-get-objectid xyz)
xyz (mapcar 'vl-prin1-to-string xyz)
)
(if (= (type new) 'ename) (setq new (list new)))
(setq new (mapcar 'vlax-ename->vla-object new)
new (mapcar 'vla-get-objectid new)
new (mapcar 'vl-prin1-to-string new)
)
(foreach ob xyz
(setq nn (car new) new (cdr new))
(if nn
(setq abc (vl-string-subst (strcat "(%<\\_ObjId " nn) (strcat "(%<\\_ObjId " ob) abc))
)
)
(setq obj (vlax-ename->vla-object obj))
(vla-put-textstring obj "CLEAR")
(vla-put-textstring obj abc)
)
-
Thanks for the help! :-D
Its what I needed for now....
-
How does one check to see if new object has all the same field options as the existing.
ie. old object is a circle and has radius but new object is a line so no radius is present?
I have thought about isolating the type of field through the text string and I have got it to work.
Now how do I check to see if my new entity has the same field properties as the existing one?
-
see vlax-property-available-p function
-
Thanks for the help Kozmos!
I appreciated it a lot! :-D