Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Field and objectid problem

2 REPLIES 2
Reply
Message 1 of 3
MatteoJames
960 Views, 2 Replies

Field and objectid problem

Hi all, playing with fields I have come up with writng this piece of code, that will place in a text the value written in an other text using a field.

{code}
(defun c:ccd (/ obj1_vla cd_valore obj2)
(vl-load-com)
(setq obj1_vla (vlax-ename->vla-object (car (Nentsel "\nSeleziona testo origine: ")))
cd_valore (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-objectid obj1_vla)) ">%).TextString>%")
obj2 (car (Nentsel "\nSeleziona testo di destinazione: "))
)
(vla-put-textstring (vlax-ename->vla-object obj2) cd_valore)
(entupd obj2)
(princ)
)
{code}

This works fine on my computer. But on an other computer that I have, the objectid of the first selected object is only a two digit number like "67" and the code posted doesn't give the right field code.

Both use Civil 3D 2009 and Windows vista.

Hope that I have been clear and that someone can help me.

Matteo.
2 REPLIES 2
Message 2 of 3
msclout72
in reply to: MatteoJames

;;;;;;;;insert field link from text to text field link;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:textfield ( / src dest oSrc oDest )
(vl-load-com)
(setq src (nentsel "\nFirst text: "))
(setq dest (nentsel "\nSecond text: "))
(setq oSrc (vlax-ename->vla-object (car src)))
(setq oDest (vlax-ename->vla-object (car dest)))
(vla-put-TextString oDest(strcat "%<\\AcObjProp Object(%<\\_ObjId "(itoa (vla-get-ObjectId oSrc))">%,1).TextString>%"))
(vla-regen (vla-get-document oDest) :vlax-true)
(princ)
)


;******insert field link from text to block attribute***********************************************************
(defun C:attfield ( / ss x blk att atts blockname tagname NewValue blkname elist tagval_id dest oDest); Change Attribute Tag..
(vl-load-com)
(setq tagval_id "NOSUCHFIELD")
;get mtext information
(setq src (nentsel "\nSelct Text or Mtext for Insert as Field: "))
(setq oSrc (vlax-ename->vla-object (car src)))
(setq tagval_id (strcat (rtos (vla-get-objectId oSrc) 2 0)))
(setq tagname2 (getstring "\nInsert Text/Mtext value as field into which ATT-TAG BLOCK?: "))
;(setq tagname2 "ATT-03")
(setq ss nil)
;; Case, you want to Pick Them..
(prompt "Pick Block for Destination Field:")
(setq ss (ssget)); pick individual, Window, Crossing.. etc.
(if ss
(progn
(setq x 0)
(repeat (sslength ss)
(setq blk (vlax-ename->vla-object (ssname ss x)))
(setq elist (entget (ssname ss x)))
(setq blkname (cdr (assoc 2 elist)))
(progn
(if (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk))))
(progn
(setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))))
(foreach att atts
(setq tag (strcase (vla-get-tagstring att))); tagname
(if (= tagname2 tag)
(vla-put-TextString att (strcat "%<\\AcObjProp Object(%<\\_ObjId " tagval_id ">%,1).TextString>%"))

); if
(vla-regen (vla-get-document att) :vlax-true)
); foreach
); progn
); if
); progn
(setq x (+ x 1))
); repeat length ss
); progn
); if
(setq tagval_id "NOSUCHFIELD")
(princ)
); end attfield function
;***********************************************************************************************

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;lisps below is how to get fields;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;this below show how to get field id's for blocks;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;FROM AUTODESK DISCUSSION AND FORUM GROUPS
(defun c:GetObjID (/ ecode obj objName)
(vl-load-com)
(while (setq ecode (entsel "\nSelect entity for objectID: "))
(setq obj (vlax-ename->vla-object (car ecode)) objName (vla-get-objectName obj))
(setq nObj (if (member objName '("AcDbBlockReference" ))(nentselp (cadr ecode))))
(princ (strcat "\rObject: "objName" ObjectID: "(rtos (vla-get-objectId obj) 2 0)" Handle: "
(vla-get-handle obj)))
(if (and nObj (setq nObj (vlax-ename->vla-object (car nObj))))
(princ (strcat "\nNested Object: "(vla-get-objectName nObj)" ObjectID: "(rtos (vla-get-objectId nObj) 2 0)" Handle: "
(vla-get-handle nObj)))
)
)
(princ)
)
;;;;;;;;;;;;;;;or this below show how to get field id's for blocks with att;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;--------------------------------------------------------------------------------------------------
(defun c:GetObjectID-1 (/ i ss objs vgms objTable row col)
(if (setq i 0 ss (ssget (list '(0 . "INSERT"))))
(while (< i (sslength ss))
(if (and (setq obj (vlax-ename->vla-object (ssname ss i)))(vla-get-hasattributes obj))
(foreach attr (vlax-invoke obj 'GetAttributes)
(if (= (vla-get-TagString attr) "+KOTE")
(princ (strcat "\nObjectID: "(rtos (vla-get-objectId attr) 2 0)" Handle: " (vla-get-handle attr))))
)
)
(setq i (1+ i))
)
)
(princ)
)
;;;;;;;;;;;;;;;or this below show how to get field id's for blocks with attributes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:GetObjectID-2 (/ ss objs)
(if (setq ss (ssget (list '(0 . "INSERT"))))
(progn
(setq objs (mapcar 'vlax-ename->vla-object
(vl-remove-if-not (function(lambda (x)(= (type x) 'ENAME)))(mapcar 'cadr (ssnamex ss)))))
(foreach obj objs
(foreach attr (vlax-invoke obj 'GetAttributes)
(if (= (vla-get-TagString attr) "+KOTE")
(princ (strcat "\nObjectID: "(rtos (vla-get-objectId attr) 2 0)" Handle: " (vla-get-handle attr))))
)
)
)
)
(princ)
)
;;;;;;;;;;;;;;;or this below show how to get field id's for blocks attributes;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:GetObjectID-3 (/ ss objs)
(if (setq ss (ssget (list '(0 . "INSERT"))))
(progn
(setq objs (mapcar 'vlax-ename->vla-object
(vl-remove-if-not (function(lambda (x)(= (type x) 'ENAME)))(mapcar 'cadr (ssnamex ss)))))
(mapcar (function (lambda(obj)
(mapcar (function (lambda(attr)
(if (= (vla-get-TagString attr) "+KOTE")
(princ (strcat "\nObjectID: "(rtos (vla-get-objectId attr) 2 0)" Handle: " (vla-get-handle attr))))
)) (vlax-invoke obj 'GetAttributes))
)) objs)
)
)
(princ)
)


;;;;;;;;;;;;;;;or thise below show how to get field id's for text or blocks;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:GetObjID (/ ecode obj objName textoratt)
(vl-load-com)
(setq textoratt (getstring 1 (strcase"\nGetObjid of Text enter T or Block Attribute A:")))
;***********************************************************TEXT SECTION GETOBJID*************
(if
(= textoratt "T")
(progn
(while (setq ecode (entsel "\nSelect entity for objectID: "))
(setq obj (vlax-ename->vla-object (car ecode)) objName (vla-get-objectName obj))
(setq nObj (if (member objName '("AcDbBlockReference" ))(nentselp (cadr ecode))))
(princ (strcat "\rObject: "objName" ObjectID: "(rtos (vla-get-objectId obj) 2 0)" Handle: "
(vla-get-handle obj)))
(if (and nObj (setq nObj (vlax-ename->vla-object (car nObj))))
(princ (strcat "\nNested Object: "(vla-get-objectName nObj)" ObjectID: "(rtos (vla-get-objectId nObj) 2 0)" Handle: "
(vla-get-handle nObj)))
)
)
);END IF
);END PROGN
;***********************************************************BLOCK ATTRIBUTE SECTION*************
(if
(= textoratt "A")
(progn
(setq tagname (getstring "\nGet OBJid of Which Tag: "))
(if (setq i 0 ss (ssget (list '(0 . "INSERT"))))
(while (< i (sslength ss))
(if (and (setq obj (vlax-ename->vla-object (ssname ss i)))(vla-get-hasattributes obj))
(foreach attr (vlax-invoke obj 'GetAttributes)
(if (= (vla-get-TagString attr) tagname)
(princ (strcat "\nObjectID: "(rtos (vla-get-objectId attr) 2 0)" Attribte Handle: " (vla-get-handle attr) " Block Handle: " (vla-get-handle obj))))
; (princ (strcat "\nObjectID: "(rtos (vla-get-objectId attr) 2 0)" Handle: " (vla-get-handle attr))))
)
)
(setq i (1+ i))
)
)
);END IF
);END PROGN
;***********************************************************BLOCK ATTRIBUTE SECTION*************
(princ)
)

Edited by: msclout72 on Apr 29, 2009 2:53 PM

Edited by: msclout72 on Apr 29, 2009 2:53 PM Edited by: msclout72 on Apr 29, 2009 2:54 PM
Message 3 of 3
H.vanZeeland
in reply to: MatteoJames

Hi,

I think it's a 64bits machine
You can try it with
(vlax-invoke-method
(vla-get-Utility
(vla-get-activedocument
(vlax-get-acad-object)))
"GetObjectIdString"
(vlax-ename->vla-object (car (nentsel)))
:vlax-False)



;------------------------------------------------ Get-ObjectIDx64 ------------------
;; function to get the ID string from a object
; (Get-ObjectIDx64 (car (entsel)))
(defun Get-ObjectIDx64 (obj / util)
(setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))))
(if (= (type obj) 'ENAME)(setq obj (vlax-ename->vla-object obj)))
(if (= (type obj) 'VLA-OBJECT)
(if (> (vl-string-search "x64" (getvar "platform")) 0)
(vlax-invoke-method util "GetObjectIdString" obj :vlax-False)
(rtos (vla-get-objectid obj) 2 0)
)
)
)

Or use (Get-ObjectIDx64 (car (nentsel)))

Cheers
Harrie

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost