TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Rabbit on June 22, 2011, 12:36:08 PM
-
I think it may be a syntax problem with vla-ObjectIDToObject32
;used to get Object Id from a field code
(setq PlineObjId (substr PlineFieldCode (+ (vl-string-search "ObjId" PlineFieldCode) 7) 13))
;returns the ObjectId numbers as a string
;I'm trying to use this to find the entity (lwpolyline) tied to the Object Id from above.
;I'm having trouble finding anything on the web which shows how to use vla-ObjectIDToObject32
;I've tried real, string and integer forms of the PlineObjectID
(vla-ObjectIDToObject32 (vla-get-activedocument (vlax-get-acad-object)) (atoi PlineObjId))
Thanks,
Rabbit
-
The problem will most likely be using atoi, since I would think the ObjectIDtoObject32 method requires a long on 64-bit systems. I suffered the same problem using atoi with the SetBlockTableRecordID32 method on a table.
-
I'm not sure what a LONG is. Is it an iteger or real. Or, is it an integer with decimal places, I.E. 12345.67
Cunfused,
Rabbit
-
A Long is a data type that holds an integer value but occupies more memory (8 bytes on a 64-bit machine) than the (Short) Integer data type. It is equivalent to a 64-bit Integer - this (http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.71%29.aspx) will give a better insight. When you use the atoi function, this truncates the string to the size of a 32-bit integer and so you lose some information.
Maybe the following will help - it will retrieve the Entity name of the entity referenced by the Field (which could then be converted to a VLA-Object if specifically required).
(defun Field->Entity ( en )
(cond
(
(and
(wcmatch (cdr (assoc 0 (setq en (entget en)))) "TEXT,MTEXT,ATTRIB")
(setq en (cdr (assoc 360 en)))
(setq en (dictsearch en "ACAD_FIELD"))
(setq en (dictsearch (cdr (assoc -1 en)) "TEXT"))
(setq en (cdr (assoc 360 en)))
(setq en (cdr (assoc 331 (entget en))))
)
en
)
)
)
Supply it with the Ename of the entity containing the field (MText, Text, Attrib).
-
I'm still not sure why I'm not able to put in a 13 digit number into the function as a LONG and it not work.
Here's all my code. The table has acell with a field with the area of a closed lwpolyline.
(defun c:GetCellFieldCode ( / eText oText)
;;;Selects a table
;;;
;;;Code:
;;;(setq id (IdMtextTable (car (entsel))))
(setq id (IdMtextTable (setq TableEntity (ssname (ssget "X" (list (cons 0 "acad_table") '(8 . "E-LGHT-CALC-SCHEDULE"))) 0))))
(setq TAbleRowCount (vlax-get-property (vlax-ename->vla-object TableEntity) 'Rows))
(setq TAbleRowCount (vlax-get-property (vlax-ename->vla-object TableEntity) 'Columns))
;;;To find at row 4 and column 1
;;;
;;;Code:
(setq ent (mapcar 'caddr (vl-remove-if-not '(lambda (x) (and (eq (car x) 3) (eq (cadr x) 2))) id)))
(setq PlineFieldCode (vla-fieldcode (car ent)))
(setq PlineObjId (substr PlineFieldCode (+ (vl-string-search "ObjId" PlineFieldCode) 7) 13))
(vla-ObjectIDToObject32 (vla-get-activedocument (vlax-get-acad-object)) (atoi PlineObjId))
);defun
;;;--------------Sub Routine-------------
(defun IdMtextTable(tab / col ent fus id lig lst)
(setq ent (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (cdr (assoc 2 (entget tab)))))
(vlax-map-collection ent '(lambda (x) (and (vlax-property-available-p x 'AttachmentPoint) (setq lst (cons x lst)))))
(setq lst (reverse lst) lig 0 tab (vlax-ename->vla-object tab))
(while (< lig (vla-get-rows tab))
(setq col 0)
(while (< col (vla-get-columns tab))
(or (eq (vla-ismergedcell tab lig col 0 0 0 0) :vlax-false)
(eq lig 0)
(eq (vla-ismergedcell tab (1- lig) col 0 0 0 0) :vlax-false)
(not (eq (cadr (vlax-invoke tab 'GetAttachmentPoint lig col))(cadr (vlax-invoke tab 'GetAttachmentPoint (1- lig) col))))
(setq fus T)
)
(or (eq (vla-ismergedcell tab lig col 0 0 0 0) :vlax-false)
(eq col 0)
(eq (vla-ismergedcell tab lig (1- col) 0 0 0 0) :vlax-false)
(not (eq (car (vlax-invoke tab 'GetAttachmentPoint lig col))(car (vlax-invoke tab 'GetAttachmentPoint lig (1- col)))))
(setq fus T)
)
(or fus
(eq (vla-gettext tab lig col) "")
(setq id (cons (list lig col (car lst)) id)
lst (cdr lst)
)
)
(setq col (1+ col) fus nil)
)
(setq lig (1+ lig))
)
(reverse id)
)
-
I'm still not sure why I'm not able to put in a 13 digit number into the function as a LONG and it not work.
Because as I just explained, you are using atoi which will convert it to a 32-bit signed integer which can only hold 10 digits (2,147,483,647)
-
Why instead of (atoi PlineObjId) not to use (read PlineObjId)?
PS Found Change Field Object in Mtext (http://www.theswamp.org/index.php?topic=21959.0)
-
Why instead of (atoi PlineObjId) not to use (read PlineObjId)?
Прослушать
Nice idea VVA.
-
Why instead of (atoi PlineObjId) not to use (read PlineObjId)?
[/quote]
Nice idea VVA.
[/quote]
Not working. I keep getting an error message "lisp has no coercion to VARIANT with this (I can't read the rest because the error box cut it off)"
How can I just take a 13 digit string and change it to a LONG data-type. Is it a variant? Do I use (vlax-make-variant PlineObjId vlax-vbLong) somehow? I'm lost here.
-
Hi,
AutoLISP do not know longs (only 32 bits integer between -2147483648 and 2147483648).
IMO there's no way to use the ObjectIdToObject32 with LISP but this can be done with other languages/environments which deal with the AutoCAD Automation API (as VB(A), .NET or objectARX).
-
IMO there's no way to use the ObjectIdToObject32 with LISP but this can be done with other languages/environments which deals with COM/ActiveX (as VB(A), .NET or objectARX).
I can only think of perhaps:
(vla-objectidtoobject32 <doc> (vla-get-objectid32 <object>))
(vla-objectidtoobject32 <doc> (vla-getblocktablerecordid32 <object> <row> <column>))
But, since the first is pointless, the cases are limited I would think...
-
Rabbit, why not use my earlier code to get the object directly without using the ObjectID?
-
Rabbit, why not use my earlier code to get the object directly without using the ObjectID?
(Field->Entity (vlax-vla-object->ename (car ent)))
It gave me a lwpolyline. I got lucky somehow. I couldn't get it work before. I wasn't doing something right.
Now to see if I can use this to finish out my code.
I'll let ya' know if I get it to work
Thanks, Rabbit
-
I'm still not sure why I'm not able to put in a 13 digit number into the function as a LONG and it not work.
Here's all my code. The table has acell with a field with the area of a closed lwpolyline.
Hello ...
Can you post a table with a polyline for example?
the subject is very interesting
Regards
-
Sofito,
To easily recreate the scenario, on a 64-bit machine, create an MText field referencing say, the area, of an LWPolyline. Then attempt to retrieve the LWPolyline object/entity from only the MText field.
Lee
-
Hi,
You can try this way (it returns an ename)
(cdr
(assoc 331
(entget
(cdr
(assoc 360
(entget
(cdr
(assoc 360
(entget
(cdr
(assoc 360
(entget
(cdr
(assoc 360
(entget
(car (nentsel "\nSelect a field: ")))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
-
The upper code is from this quite old one:
;;; FLD-OBJ -Gilles Chanteau- 16/12/06
;;; Highlights the linked object to the selected field
;;; An option allows to create a line from the fied to the object
;;; Works with fields in tables and blocks
(defun c:fld-obj (/ ent txt elst dic chp obj)
(while
(not
(and (setq ent (nentsel "\nSelect a field: "))
(setq txt (car ent))
(setq elst (entget txt))
(member (cdr (assoc 0 elst)) '("*TEXT" "ATTRIB"))
)
)
(princ "\nNone field selected.")
)
(if (and (setq dic (cdr (assoc 360 elst)))
(setq dic (cdr (assoc 360 (entget dic))))
(setq chp (cdr (assoc 360 (entget dic))))
(= (cdr (assoc 0 (entget chp))) "FIELD")
(setq chp (cdr (assoc 360 (entget chp))))
)
(if (setq obj (cdr (assoc 331 (entget chp))))
(progn
(redraw obj 3)
(initget "Yes No")
(if
(= "Yes"
(getkword "\nLink the object to the text ? [Yes/No] <No>: ")
)
(entmake (list '(0 . "LINE")
(cons 10
(if (< 2 (length ent))
(setq pt
(mapcar '+
(cdr (assoc 10 (entget (car (last ent)))))
(cdr (assoc 10 elst))
)
)
(setq pt (cdr (assoc 10 elst)))
)
)
(cons 11 (cdr (assoc 10 (entget obj))))
)
)
)
)
(princ "\nThe field isn't linked to an object.")
)
(princ "\nthe textdo not contains a field.")
)
(princ)
)
-
Sofito,
To easily recreate the scenario, on a 64-bit machine, create an MText field referencing say, the area, of an LWPolyline. Then attempt to retrieve the LWPolyline object/entity from only the MText field.
Lee
Hello....
I already do, even with the volume of a 3dsolid ( attached ) .... was messing with something more formalized table included. I tried to make the table and fill it in as Rabbit makes ....
Thanks, Greetings