TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Andrea on July 11, 2017, 10:06:25 AM

Title: retreive ename from string
Post by: Andrea on July 11, 2017, 10:06:25 AM
Hi all,..

in some existing lisp....ther is a value created in XDATA as a string like this:

Code: [Select]
"(<Entity name: c5481b5d30>)"
so I don'T know why this guy made this things,..
but now i'm trying to retreive theses entities.

I mean,...to get
Code: [Select]
<Entity name: c5481b5d30>using (car (read (... doenst work..

even more,....there is mix up with "(#<VLA-OBJECT IAcadBlockReference 000000c5483955a8)"

so maybe there is another way..that I dont know.
thank you for your help.
Title: Re: retreive ename from string
Post by: kpblc on July 11, 2017, 10:27:22 AM
I see only one way (too slow, too stupid): check all database and compare entity pointers to this string.
Title: Re: retreive ename from string
Post by: Andrea on July 11, 2017, 10:30:33 AM
this is exacly what the program do...and I can tell you how slow it is... :(
so that's why I want to change his method,..

the fact is that it must work in existing drawing who contain this information..
so i'm trying to find a work around.. :tickedoff:

actually I've replaced the ename and vl-name by the Handle name,....much faster with handent
but I've some issue also with this,..because handle seem can not be retreived for entities in XREF.
:(
Title: Re: retreive ename from string
Post by: roy_043 on July 11, 2017, 10:51:46 AM
32 bit BricsCAD:
Code: [Select]
: (setq enm (car (entsel)))
Select entity: <Entity name: 19157418>
: (setq str (vl-string-right-trim ">" (substr (vl-princ-to-string enm) 15)))
"19157418"
: (KGA_Math_Hex_To_Dec str)
420836376
: (vla-get-objectid (vlax-ename->vla-object enm))
420836376
Note: enames will change between sessions. So storing them in Xdata makes little sense.
Title: Re: retreive ename from string
Post by: ronjonp on July 11, 2017, 10:57:53 AM
32 bit BricsCAD:
Code: [Select]
: (setq enm (car (entsel)))
Select entity: <Entity name: 19157418>
: (setq str (vl-string-right-trim ">" (substr (vl-princ-to-string enm) 15)))
"19157418"
: (KGA_Math_Hex_To_Dec str)
420836376
: (vla-get-objectid (vlax-ename->vla-object enm))
420836376
Note: enames will change between sessions. So storing them in Xdata makes little sense.
Precisely .. handles make more sense.
Title: Re: retreive ename from string
Post by: Andrea on July 11, 2017, 11:13:12 AM
32 bit BricsCAD:
Code: [Select]
: (setq enm (car (entsel)))
Select entity: <Entity name: 19157418>
: (setq str (vl-string-right-trim ">" (substr (vl-princ-to-string enm) 15)))
"19157418"
: (KGA_Math_Hex_To_Dec str)
420836376
: (vla-get-objectid (vlax-ename->vla-object enm))
420836376
Note: enames will change between sessions. So storing them in Xdata makes little sense.

is Briscad use only numeric value ad objectID ?
in autoCAD :
Code: [Select]
<Entity name: bd3fe7c660>
Title: Re: retreive ename from string
Post by: roy_043 on July 11, 2017, 11:20:12 AM
is Briscad use only numeric value ad objectID ?
The ename is a hex value, same as AC, hence KGA_Math_Hex_To_Dec.
Title: Re: retreive ename from string
Post by: Andrea on July 11, 2017, 11:25:06 AM
is Briscad use only numeric value ad objectID ?
The ename is a hex value, same as AC, hence KGA_Math_Hex_To_Dec.

any chance to share  KGA_Math_Hex_To_Dec function ?
I've supposed to use LeeMac LM:Hex->Dec function who generate diffrent result.
Code: [Select]
(LM:Hex->Dec "c5481b5d30")
;3.04634e+12
Title: Re: retreive ename from string
Post by: Andrea on July 11, 2017, 11:40:38 AM
maybe if I can't retreive object from handle name inside an XREF,..

Code: [Select]

(setq item (car (last (nentsel))))
  ;<Entity name: bd33651530>
(setq hand (cdr (assoc 5 (entget item))))
  ;"27B"
(handent hand)
  ;nil <---- ???
Title: Re: retreive ename from string
Post by: roy_043 on July 11, 2017, 11:50:43 AM
any chance to share  KGA_Math_Hex_To_Dec function ?

The function I have used will not work properly if the hex value exceeds the 32 bit range.
Try:
Code: [Select]
(rtos (LM:Hex->Dec "c5481b5d30") 2 0)
FWIW my function:
Code: [Select]
; (KGA_Math_Hex_To_Dec "7FFFFFFF") => 2147483647
; (KGA_Math_Hex_To_Dec "37CD")     => 14285
; (KGA_Math_Hex_To_Dec "0")        => 0
(defun KGA_Math_Hex_To_Dec (str)
  (KGA_Math_Base_To_Dec str 16)
)

; (KGA_Math_Base_To_Dec "11111111" 2) => 255
; (KGA_Math_Base_To_Dec "37cd" 16)    => 14285
(defun KGA_Math_Base_To_Dec (str base / i)
  (setq i -1)
  (fix
    (apply
      '+
      (mapcar
        '(lambda (a)
          (* (- a (cond ((<= a 57) 48) ((<= a 90) 55) (87))) (expt base (setq i (1+ i))))
        )
        (reverse (vl-string->list str))
      )
    )
  )
)
Title: Re: retreive ename from string
Post by: roy_043 on July 11, 2017, 11:58:49 AM
maybe if I can't retreive object from handle name inside an XREF,..
The handent function only works for the current document. Try using the HandleToObject method instead.
Title: Re: retreive ename from string
Post by: Andrea on July 11, 2017, 12:31:29 PM
maybe if I can't retreive object from handle name inside an XREF,..
The handent function only works for the current document. Try using the HandleToObject method instead.
oh.. maybe this can help me...never use it,..

how the syntax must be ?
Code: [Select]
(vla-HandleToObject (vla-get-ActiveDocument (vlax-get-acad-object)) handle) return me :
Automation Error. Unknown handle

?
Title: Re: retreive ename from string
Post by: MP on July 11, 2017, 12:54:00 PM
Logic suggests you would have to open the hosting XREF as an ODBX doc, and then invoke the HandleToObject method from said doc.

i.e.

Code: [Select]
(if (eq 'vla-object (type (setq object (vl-catch-all-apply 'vla-HandleToObject (list ODBX handle)))))
    (rock_and_roll_with object)
    (sad_trombone)
)

Untested & no time to play.
Title: Re: retreive ename from string
Post by: MP on July 11, 2017, 01:01:04 PM
<works>
Title: Re: retreive ename from string
Post by: CAB on July 11, 2017, 01:08:55 PM
That's why I love this place.
The impossible just takes longer and finding the right guy.  8)
Title: Re: retreive ename from string
Post by: Andrea on July 11, 2017, 01:14:00 PM
Thank you Mickael,.

but I cannot use dbx here..for many restriction.

there is my goal,
1) capture block inside an XREF
2) get the attribute value
3) get the objectID
4) create Field

it work...until the XREF is changed,..then the ObjectID also changed.,..and Field show ####
so the only thing who stay constant is handle...then I think that I can do something with this.

however,...I've 2 problematic..

1) some items contain xdata value of ename or vl-object as string that I cannot reuse...
Code: [Select]
(read "(<Entity name: c5481b5d30>)")) who is the object name of block attribute.

2) get object information inside an XREF via handle name. it work only if the handle is part of the current drawing.

I can filter items in XREF and then get the correct one,...but this method is tooo slow !..

so I don't really know how to think on this concept..
Title: Re: retreive ename from string
Post by: Lee Mac on July 11, 2017, 01:45:55 PM
A bit late to the party, but you may want to refer to my LM:ename->objectid function as used in this program (http://lee-mac.com/areafieldtoattribute.html) - this function will also handle 64-bit Object IDs.
Title: Re: retreive ename from string
Post by: Andrea on July 11, 2017, 02:16:02 PM
Thank you Lee, the problem is to retreive attribute value in specific bloc inside an XREF.
Title: Re: retreive ename from string
Post by: Andrea on July 11, 2017, 04:47:03 PM
Finally,..I've copmpletly remake the tool..
to bad for the existing drawings..

Thank you for your Help.