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

Return Text Value

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
Anonymous
1837 Views, 13 Replies

Return Text Value

Im new to lisp and I've reached a point that I just can't seem to get past.  Im trying to select text from a specific point on the drawing and set the value of that text as a variable to return later.  Im stuck at selecting the text and saving the value.  I've tried the vla-get-textstring method shown in acadauto.chm file but it shows how to create a text and then return it. Any help would be greatly appreciated.  

 

 

(setq p1 (list 30.4248 2.2476)); top point of selection box for detailer name in title block
(setq p2 (list 31.5532 2.4448)); bot point of selection box for detailer name in title block

(setq p3 (list 25.2794 1.3583)); mid point of detailer name in rev box

(setq detname (???? p1 p2))

(command "text" "S" "STANDARD" "J" "M" p3 0.1 0 detname)

 

Thanks,

Jeremy

13 REPLIES 13
Message 2 of 14
hmsilva
in reply to: Anonymous

Something like this perhaps.

 

(setq p1 (list 30.4248 2.2476)); top point of selection box for detailer name in title block
(setq p2 (list 31.5532 2.4448)); bot point of selection box for detailer name in title block
(setq p3 (list 25.2794 1.3583)); mid point of detailer name in rev box
(if (setq txt (ssget "C" p1 p2 '((0 . "TEXT"))));; creates a selectionb set using a crossing selection, see if a 
  (progn
(setq detname (cdr (assoc 1 (entget (ssname txt 0)))));; gets the text string
(command "text" "S" "STANDARD" "J" "M" p3 0.1 0 detname)
);; progn
  );; if
  

HTH

Henrique

EESignature

Message 3 of 14
ezcad.co.uk
in reply to: Anonymous

Jeremy, something you may want to think about...

I gather from your post that you are trying to read text from a specific location on a drawing border & recreate it at another location?

This being the case...the code you have posted & the solution which you have been offered can produce unpredictable results. Your approach assumes that the text source & destination positions will always be the same. However, what happens if a user moves or places the drawing border at a different location than that which is expected? A far better approach would be to have the drawing border as a block with pre-defined & uniquely named attributes at the source & destination positions. Then you could test to see if the block is present in the drawing & if so look for the specific attributes, get the value of one & then write it into the other. As you have said, you are fairly new to AutoLisp and I am not trying to pick your code apart or demean you in any way, but sometimes when you assume & write "hard coded" values into your programs you can end up with unpredictable results. One vital lesson I learned when writing code is to understand that you cannot make assumption...everything must be tested & varified before trying to perform an action. If you would like to discuss this further, I am quite happy for you to PM me & I will do my best to help you along.

Steve

Message 4 of 14
Anonymous
in reply to: Anonymous

Henrique I appreciate you helping with the code. As soon as I can I will test it out.

Steve I also appreciate your comments and will keep what you said in mind for future things I do. I recently started a new job and I'm trying to work on some of the existing lisp programs we currently have. I would like to make the title block a block with attributes but I don't know if that would be something the company would allow me to change. The way the program is written, the text I'm wanting to select should be in the same spot every time unless as you said the drawing is moved. But I do have a dialog box that appears to give the user the option to check to make sure the program was run correctly. Again I greatly appreciate the help.
Jeremy
Message 5 of 14
hmsilva
in reply to: Anonymous


@Anonymous wrote:
Henrique I appreciate you helping with the code. As soon as I can I will test it out.

You're welcome, Jeremy.

 

Keep in mind that using "ssget" function with the crossing or window option, requires that the selected object be visible, to do this you may use a zoom command just before the selection,

i.e.
using your points
(command "_zoom" "_w" p1 p2)
or a zoom extents, then do the selection stuff, and then
(command "_zoom" "_P")
restores the previous zoom.

 

Hope that helps
Henrique

EESignature

Message 6 of 14
Anonymous
in reply to: Anonymous

Henrique I had actually ran into that scenario just recently where certain pieces of text would not be deleted because i was not zoomed out enough. It took me a little while to figure that one out. I couldn't understand why the program worked sometimes and then didn't other times. Finally realized it was due to being in too close. I appreciate that tip. I will make sure to include it in this program.

Jeremy.
Message 7 of 14
Lee_Mac
in reply to: Anonymous

Indeed, any graphical selection method will only select those objects visible within the drawing area at the time of selection.

 

Here is an alternative method that should perform successfully independent of zoom:

 

(defun c:test ( / txt )
    (if
        (setq txt
            (ssget "_X"
               '(
                    (0 . "TEXT")
                    (-4 . ">=,>=")
                    (10 30.4248 2.2476)
                    (-4 . "<=,<=")
                    (10 31.5532 2.4448)
                )
            )
        )
        (entmake
            (list
               '(00 . "TEXT")
               '(07 . "Standard")
               '(10 25.2794 1.3583)
               '(11 25.2794 1.3583)
               '(72 . 4)
               '(73 . 0)
               '(40 . 0.1)
                (assoc 1 (entget (ssname txt 0)))
            )
        )
    )
    (princ)
)

 

Here are some links to help you understand the code:

 

TEXT DXF Reference

ssget Function Reference

 

 

Message 8 of 14
Anonymous
in reply to: Anonymous

Henrique and Lee_mac thanks for both of your help. Both of your programs worked exactly as I was needing. Also Lee I appreciate the links. Thanks again.

Jeremy
Message 9 of 14
hmsilva
in reply to: Anonymous

@ JeremyD79

 

You're welcome, Jeremy.
Happy to help!

 

@ Lee Mac

 

Nice approach Lee!
Just a thought, should not be used a active layout filter, if we have multiple instances in multiple layouts the result may not be the desired...

 

Henrique

EESignature

Message 10 of 14
Lee_Mac
in reply to: Anonymous


@Anonymous wrote:
Henrique and Lee_Mac thanks for both of your help. Both of your programs worked exactly as I was needing. Also Lee I appreciate the links. Thanks again.

Jeremy

You're welcome Jeremy Smiley Happy

 


@hmsilva wrote:

Nice approach Lee!
Just a thought, should not be used a active layout filter, if we have multiple instances in multiple layouts the result may not be the desired...


Thank you Henrique Smiley Happy

 

Good point about the layout filter, perhaps the following code would be better:

 

(defun c:test ( / txt )
    (if
        (setq txt
            (ssget "_X"
                (list
                   '(0 . "TEXT")
                   '(-4 . ">=,>=")
                   '(10 30.4248 2.2476)
                   '(-4 . "<=,<=")
                   '(10 31.5532 2.4448)
                    (if (= 1 (getvar 'cvport))
                        (cons 410 (getvar 'ctab))
                       '(410 . "Model")
                    )
                )
            )
        )
        (entmake
            (list
               '(00 . "TEXT")
               '(07 . "Standard")
               '(10 25.2794 1.3583)
               '(11 25.2794 1.3583)
               '(72 . 4)
               '(73 . 0)
               '(40 . 0.1)
                (assoc 1 (entget (ssname txt 0)))
            )
        )
    )
    (princ)
)

 

Message 11 of 14
hmsilva
in reply to: Lee_Mac

Lee_mac wrote:


Thank you Henrique Smiley Happy

 

You're welcome, Lee Smiley Happy

 

Good point about the layout filter, perhaps the following code would be better:

 

As usual, a very good solution! Smiley Wink

 

Henrique

EESignature

Message 12 of 14
scot-65
in reply to: Anonymous

Still yet another method for catching desired objects (a little more complicated, but does not require blocks with attributes).

Each object has a handle. The DFX code for this handle is 5. The value assigned to DFX 5 will never change (so I am told).

Investigate VLAX-LDATA-GET and VLAX-LDATA-PUT to retrieve and store the object's handle in the file's dictionary.

If you want to store and retrieve multiple handles, investigate LIST.

The selection set SSGET "X" will require a filter - use the value that was stored from the dictionary.

Test to see if the selection set has the object.

If it does - you now have your desired object where you can now extract the data you need.

 

Rereading your post a second time it looks like you are trying to erase the existing text and adding a new text object in it's place???

>>Im trying to select text from a specific point on the drawing...

Look into ENTMOD and (CDR (ASSOC 1 (ENTGET (SSNAME [your selection set] 0)))) to rewrite DFX code 1, which is the text value (display).

 

If there is no text to select, then do as the first paragraph suggests but choose another object (such as a line) and POLAR (from DFX 10)

to the desired location you want to place the new text object.

 

Since you are a beginner, enter the following on the command line and select an object:

(entget (car (entsel "Select an object: ")))

 

Do you see all the DFX codes? Learn what each means and you will be an expert in no time...

 

Hope this helps.


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 13 of 14
Lee_Mac
in reply to: scot-65


@scot-65 wrote:

Investigate VLAX-LDATA-GET and VLAX-LDATA-PUT to retrieve and store the object's handle in the file's dictionary.

The selection set SSGET "X" will require a filter - use the value that was stored from the dictionary.


Note that the filter list argument of the ssget function cannot be used to filter for entity handles:

 

The ssget function recognizes all group codes except entity names (group -1), handles (group 5), and xdata codes (groups greater than 1000).

 

(Source)

Message 14 of 14
scot-65
in reply to: Lee_Mac

Then yet another method:
Register an application -
(regapp "DWG_NAME")
Apply to an existing object:
(entmod (append (entget (car d)) '( (-3 ("DWG_NAME" (1000 . "A Drawing Name Object"))))))
To grab the entity:
(ssget "x" '( (-3 ("DWG_NAME"))))
I have used this method for quite some time, however the downside to this is when others copy this object to be used elsewhere in the page, the copied object is also updated.

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


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

Post to forums  

Autodesk Design & Make Report

”Boost