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

Get text value question

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
richie_hodgson
2018 Views, 10 Replies

Get text value question

Hi guys i am going a little mental trying to goet a little bit of code working, essentially what I want is to be able to select some text on the screen and use that text in a routine as per attached i think i am having issues with the following bit (setq im (ssname (ssget "\nPick Tile text to Extract Image:\n" '((0 . "TEXT"))) 0)) <---problem here possibly (if (setq Found (assoc IM DataList)) (progn (print Found) (setq pt1 (cdr Found)) (setq ff (strcat "s:/2012urban/" im ".jpg" )) ;strcat "c:/Civil 3D Projects/Tiles/" im ".jpg" <---so this bit doesnt work (command "-image" "A" ff pt1 "479.8697" "358.3897") ) I am going a bit senile working out where the problem is, can you help.
Richie
10 REPLIES 10
Message 2 of 11
paullimapa
in reply to: richie_hodgson

Your ssget format is incorrect. This is the acceptable formatting:

(ssget [sel-method] [pt1 [pt2]] [pt-list] [filter-list])

Your prompt will have to occur separately:

(princ"\nPick Tile text to Extract Image:")

(setq im (ssname (ssget '((0 . "TEXT"))) 0))

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 11
richie_hodgson
in reply to: paullimapa

Thanks for that, I worke out the following works as well

 

(setq obj1 (car (entsel "\nSelect the text string ")))
     (setq IM (vla-get-textstring (vlax-ename->vla-object OBJ1)))

 

thanks again.

 

Will try your method as it will only select text whereas mine may throw an error if something else is selected.

Richie
Message 4 of 11
paullimapa
in reply to: richie_hodgson

You have to be careful with (entsel...since this will allow you to select other objects and not just Text which would crash the rest of your code.

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 11
richie_hodgson
in reply to: paullimapa

Hi

 

I tried your method in the code and it didn't perform the function, i think it has promis though, essentially there is a grid of text relating to image tiles. With my method you select the text and it puts the relevent image tile there, select the next text and the next image tile is added. It would be nice to be able to select a bunch of those texts and then report those as a list to the insert function so a bunch of tiles get inserted in one go, but I am not yet adept enough a lisp to work that bit out. Maybe someone can help me out with that bit.

Richie
Message 6 of 11
richie_hodgson
in reply to: paullimapa

Hello again, though tabout it overnight and came up with the following modification:

(setq eset (ssget '((0 . "TEXT"))));Select grid text lables
     (setq cntr 0);setup a counter
     (while (< cntr (sslength eset));loop through all entities in the selection set  
        (setq en (nth cntr eset)); get the value of the nth item 
        (if (setq Found (assoc en DataList)); if it exists on the datalist <---- Something possibly wrong
           (progn
              (setq pt1 (cdr Found))
               (setq ff (strcat "s:/2012urban/" en ".jpg" )); add en to the file path and <---- Something possibly wrong
               (command "-image" "A" ff pt1 "479.8697" "358.3897"); put the image in the right place
             );end progn
         ); end of iff
      (setq cntr(+ cntr 1));increment the counter
    ); end of while

 

I get the following ; error: bad argument type: consp <Selection set: 1e94a> so I think there is something wrong where indicated am I missing a text conversion or something? I have a grid of text that relates to image tile names, so I want to be able to select the relevent text's and cycle through putting the image on the screen. I have attached the full lisp as it differs from the previous. Any clues as to why the error is occuring.

Richie
Message 7 of 11
paullimapa
in reply to: richie_hodgson

try replacing this line of code:

(setq en (nth cntr eset)); get the value of the nth item  

 

with this line of code:

(setq en (ssname eset cntr)); get the entity from the selection set eset at index cntr

 

And after this line of code:

(setq pt1 (cdr Found))

You're also missing this line of code that grabs the Text string from the entity which you included in the past:

(setq en (vla-get-textstring (vlax-ename->vla-object en)))

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store

 

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 8 of 11
richie_hodgson
in reply to: paullimapa

Hi

 

Thanks for that, I understood your adjustments and put them in the code but it didn't work, however I just changed the location of the

(setq en (vla-get-textstring (vlax-ename->vla-object en))) to just after the (setq en (ssname eset cntr)); get the entity from the selection set eset at index cntr and it all worked wonderfully. I need to put a few more error captures in the code but it has made a painfully slow repetitive process rather pleasent. Thanks for your help.

 

     (setq eset (ssget '((0 . "TEXT"))));Select grid text lables
     (setq cntr 0);setup a counter
     (while (< cntr (sslength eset));loop through all entities in the selection set  
        (setq en (ssname eset cntr)); get the entity from the selection set eset at index cntr
        (setq en (vla-get-textstring (vlax-ename->vla-object en))); make en a textstring value  <--- Put it here instead 
        (if (setq Found (assoc en DataList)); if it exists on the datalist <---- this needed the textstring value too
           (progn
              (setq pt1 (cdr Found)); get the insert coordinate <---Not after here
              (setq ff (strcat "s:/2012urban/" en ".jpg" )); add en to the file path and
              (command "-image" "A" ff pt1 "479.8697" "358.3897"); put the image in the right place
           );end progn
         ); end of iff
      (setq cntr(+ cntr 1));increment the counter
    ); end of while

 

 

Regards

 

Richie

 

Richie
Message 9 of 11
richie_hodgson
in reply to: paullimapa

Hi

 

Thanks for that, I understood your adjustments and put them in the code but it didn't work, however I just changed the location of the

(setq en (vla-get-textstring (vlax-ename->vla-object en))) to just after the (setq en (ssname eset cntr)); get the entity from the selection set eset at index cntr and it all worked wonderfully. I need to put a few more error captures in the code but it has made a painfully slow repetitive process rather pleasent. Thanks for your help.

 

Regards

 

Richie

 

Richie
Message 10 of 11
paullimapa
in reply to: richie_hodgson

I see your adjustments and they make perfect sense.

BTW, you may also want to include this statement at the beginning since you are using visual lisp functions (vl-...

(vl-load-com)

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 11
richie_hodgson
in reply to: paullimapa

Will do, many thanks.

Richie

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

Post to forums  

Autodesk Design & Make Report

”Boost