Author Topic: retreive ename from string  (Read 3694 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
retreive ename from string
« 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.
Keep smile...

kpblc

  • Bull Frog
  • Posts: 396
Re: retreive ename from string
« Reply #1 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.
Sorry for my English.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: retreive ename from string
« Reply #2 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.
:(
« Last Edit: July 11, 2017, 10:34:18 AM by Andrea »
Keep smile...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: retreive ename from string
« Reply #3 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.
« Last Edit: July 11, 2017, 10:54:50 AM by roy_043 »

ronjonp

  • Needs a day job
  • Posts: 7528
Re: retreive ename from string
« Reply #4 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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Andrea

  • Water Moccasin
  • Posts: 2372
Re: retreive ename from string
« Reply #5 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>
Keep smile...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: retreive ename from string
« Reply #6 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.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: retreive ename from string
« Reply #7 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
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: retreive ename from string
« Reply #8 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 <---- ???
Keep smile...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: retreive ename from string
« Reply #9 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))
      )
    )
  )
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: retreive ename from string
« Reply #10 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.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: retreive ename from string
« Reply #11 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

?
Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: retreive ename from string
« Reply #12 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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: retreive ename from string
« Reply #13 on: July 11, 2017, 01:01:04 PM »
<works>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: retreive ename from string
« Reply #14 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)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: retreive ename from string
« Reply #15 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..
Keep smile...

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: retreive ename from string
« Reply #16 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 - this function will also handle 64-bit Object IDs.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: retreive ename from string
« Reply #17 on: July 11, 2017, 02:16:02 PM »
Thank you Lee, the problem is to retreive attribute value in specific bloc inside an XREF.
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: retreive ename from string
« Reply #18 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.
Keep smile...