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

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2303
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: 248
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: 2303
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

  • Swamp Rat
  • Posts: 1440
  • BricsCAD 16
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: 6258
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 10 x64 - AutoCAD /C3D 2018

Custom Build PC

Andrea

  • Water Moccasin
  • Posts: 2303
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

  • Swamp Rat
  • Posts: 1440
  • BricsCAD 16
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: 2303
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: 2303
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

  • Swamp Rat
  • Posts: 1440
  • BricsCAD 16
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

  • Swamp Rat
  • Posts: 1440
  • BricsCAD 16
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: 2303
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: 16932
  • brevity != aggression
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.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

MP

  • Seagull
  • Posts: 16932
  • brevity != aggression
Re: retreive ename from string
« Reply #13 on: July 11, 2017, 01:01:04 pm »
<works>
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

CAB

  • Global Moderator
  • Seagull
  • Posts: 10198
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.