script to copy a text to clipboard and paste it to an attribute

script to copy a text to clipboard and paste it to an attribute

Anonymous
Not applicable
5,505 Views
13 Replies
Message 1 of 14

script to copy a text to clipboard and paste it to an attribute

Anonymous
Not applicable

Hello,

I’m writing a script to copy a text to clipboard then paste it into an attribute of a block. This will repeat in hundreds plans. The text will be in the same location so I use its coordination to catch it. The problem is that it always stops at the 3rd line (1351,22 coordinate of the text). I guess it doesn’t regonize _selall (select all) or other reasons. I am a beginner of script and lisp. Any help would be appreciated.

 

; copy text from old Mtext to clipboard
_mtextedit
1351,22
_selall
_copyclip
(command)
;
;paste it to attribute
-attedit
o
FR_ATTR-****
FEUILLET

1320,30
1365,15
1320,30
1365,15

V
_.PASTECLIP

_Qsave
_close
0 Likes
Accepted solutions (3)
5,506 Views
13 Replies
Replies (13)
Message 2 of 14

pbejse
Mentor
Mentor

@Anonymous wrote:

Hello,

I’m writing a script to copy a text to clipboard then paste it into an attribute of a block. This will repeat in hundreds plans. The text will be in the same location so I use its coordination to catch it. The problem is that it always stops at the 3rd line (1351,22 coordinate of the text). I guess it doesn’t regonize _selall (select all) or other reasons. I am a beginner of script and lisp. Any help would be appreciated.


Is that whereabouts  1551,22 or exactly at that point?

The value at clipboard will be assigned to 4 attribute tags  < FEUILLET >?

 

We can write a short code to run in conjunction with your script

 

 

 

0 Likes
Message 3 of 14

Anonymous
Not applicable

The exact point is (1351.0687, 22.0174)

yes, the attribute tag is FEUILLET

We works with French version, so there might be some words in french.

Thanks for your helop.

0 Likes
Message 4 of 14

pbejse
Mentor
Mentor

@Anonymous wrote:

The exact point is (1351.0687, 22.0174)...

Thanks for your helop.


Ok then, I will work on this tomorrow, Windows update messed up my porgramlicense for Both Civil 3d and Autocad 

 

Hang in there hifrank001.

 

0 Likes
Message 5 of 14

pbejse
Mentor
Mentor
Accepted solution

Source MTEXT <--- From here , to here --->Attribute block  on the same drawing.

 

If that is the case then we wont be needing the clipboard when using lisp program with script. We can add more filter to select the MTEXT, like layers. even knowing the height of the MTEXT would help

 

Try this code 

 

 

(defun c:demo  (/ theMtextAtAGivenCoordinate theAttributeBlock i)

      (if (and
                (setq theMtextAtAGivenCoordinate
                           (ssget "_X"
                                  '((0 . "MTEXT") (10 1551.0 22.00 0.0))))
                (setq theMtextAtAGivenCoordinate
                           (ssname theMtextAtAGivenCoordinate 0))
                (setq theMtextAtAGivenCoordinate
                           (cdr (assoc 1 (entget theMtextAtAGivenCoordinate))))
                (setq theAttributeBlock
                           (ssget "_X"  '((0 . "INSERT")
                                    (66 . 1) (2 . "FR_ATTR-XX")))))
            (repeat (setq i (sslength theAttributeBlock))
                  (foreach atb
                         (vlax-invoke
                               (vlax-ename->vla-object
                                     (ssname theAttributeBlock
                                             (setq i (1- i))))
                               'GetATtributes)
                        (if (eq (vla-get-tagstring atb) "FEUILLET")
                              (vla-put-textstring  atb
                                    theMtextAtAGivenCoordinate)))
                  )
            )
      )

 

 

The theMtextAtAGivenCoordinate variable initial value if not nil is a selection set.

There are a couple of ways to to a selection using a point, one is shown on the code above ("X"), another is using "C" and a point list

 

 

(setq theMtextAtAGivenCoordinate
                           (ssget "C" '(1551.0 22.00 0.0) '(1552.0 50.00 0.0)
                                  '((0 . "MTEXT") )))

 

problem is only objects visible in the drawing area at the time of selection will be selected by this method.

 

 

(nentselp '(1551.00 22.00))

but this will depend if the part of the object is at a given point, though one can increase the size of pickbox for a bigger range.

 ........

 AND back again to ssget "_X" , you can add range filter to make "X" behave like "C" minus the restriction of being visible in the drawing area

 

 

(setq ss (ssget "_X" '((0 . "MTEXT") (-4 . ">=,>=,*") (10 1551.0 22.0 0.0)(-4 . "<=,<=,*")
                           				  (10 1600.0 50.0 0.0) )))

And you can even add the layer name there  (8 . "MTEXTLAYERName")

 

now for the script

 

(c:demo) <---or whatever you name the lisp program
_Qsave
_close

Play around with the code, and see what works for you. 

 

 Happy coding.

 

pBe

 

Message 6 of 14

Anonymous
Not applicable

cool, I'll test it and accept it as a solution.

Thanks a lot for the attentive help.

0 Likes
Message 7 of 14

Anonymous
Not applicable

Hello, pBe,

I tested the codes and it didn’t go through; my knowledge of lisp is very primary so maybe I didn’t process it properly. A simple dwg is attached and if possible, please give it a try.

Note

  1. The block name has, T-i-t, the three letters at the end instead of xx, I assume the website has it changed automatically by sensitive word control.
  2. The entity is Text instead of Mtext
  3. It`s in paper space.

Thanks again.

0 Likes
Message 8 of 14

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Hello, pBe,

Note

  1. The block name has, T-i-t, the three letters at the end instead of xx, I assume the website has it changed automatically by sensitive word control.
  2. The entity is Text instead of Mtext

Thanks again.


Replace 

 

(setq theMtextAtAGivenCoordinate
                           (ssget "_X"
                                  '((0 . "MTEXT") (10 1551.0 22.00 0.0))))

 

With

  (setq theMtextAtAGivenCoordinate
                           (ssget "_X" '((0 . "TEXT")(410 . "~Model")(-4 . ">=,>=,*")
					 (10 1338.0 18.0 0.0)(-4 . "<=,<=,*")
                           		 (10 1364.0 26.0 0.0) )))

 

(410 . "~Model") ..........Ignore objects in Model Space
(1338.0 18.0 0.0) .........Approximate lower left corner of the target TEXT object 
(1364.0 26.0 0.0) .........Approximate upper right corner of the target TEXT object 

 

Then you're all set.

 

Message 9 of 14

Anonymous
Not applicable
Accepted solution

It works!

I know I can get help here.

I list the entire routine below as a record.

(defun c:demo  (/ theMtextAtAGivenCoordinate theAttributeBlock i)

      (if (and
              (setq theMtextAtAGivenCoordinate
                           (ssget "_X" '((0 . "TEXT")(410 . "~Model")(-4 . ">=,>=,*")
					 (10 1338.0 18.0 0.0)(-4 . "<=,<=,*")
                           		 (10 1364.0 26.0 0.0) )))
                (setq theMtextAtAGivenCoordinate
                           (ssname theMtextAtAGivenCoordinate 0))
                (setq theMtextAtAGivenCoordinate
                           (cdr (assoc 1 (entget theMtextAtAGivenCoordinate))))
                (setq theAttributeBlock
                           (ssget "_X"  '((0 . "INSERT")
                                    (66 . 1) (2 . "FR_ATTR-****")))))
            (repeat (setq i (sslength theAttributeBlock))
                  (foreach atb
                         (vlax-invoke
                               (vlax-ename->vla-object
                                     (ssname theAttributeBlock
                                             (setq i (1- i))))
                               'GetATtributes)
                        (if (eq (vla-get-tagstring atb) "FEUILLET")
                              (vla-put-textstring  atb
                                    theMtextAtAGivenCoordinate)))
                  )
            )
      )
0 Likes
Message 10 of 14

pbejse
Mentor
Mentor

@Anonymous wrote:

It works! | I know I can get help here.


Great!!  Score one for the team. 🙂  👊 < fist bum >  |    Yes you can hifrank001.

 

Happy to help

 

 

0 Likes
Message 11 of 14

Anonymous
Not applicable

I'm looking at the code and surely many things are beyond my knowledge; but one thing I dare to ask is what is the purpose of (-4 . ">=,>=,*") and (-4 . "<=,<=,*").

0 Likes
Message 12 of 14

pbejse
Mentor
Mentor

@Anonymous wrote:

I'm looking at the code and surely many things are beyond my knowledge; but one thing I dare to ask is what is the purpose of (-4 . ">=,>=,*") and (-4 . "<=,<=,*").


Equality and Conditional Functions Reference (AutoLISP) < for light reading

 

 

 (-4 . ">=,>=,*")
 (10 1338.0 18.0 0.0)
 (-4 . "<=,<=,*")
 (10 1364.0 26.0 0.0))))

      (>= 1338.0) <-- X Coordinate
More than or Equal the value of X position on a point coordinate
      (>= 18.0)   <-- Y Coordinate
More than  or Equal the value of Y position on a point coordinate

      (<= 1364.0) <-- X Coordinate
Less than or Equal the value of X position on a point coordinate
    (<= 26.0)   <-- Y Coordinate
Less than  or Equal the value of Y position on a point coordinate					      

      (* 0.0)     <-- Z Coordinate
      (* 0.0)	  <-- Z Coordinate
Match any value for Z position on a point coordinate Basically any coordinate between (1338.0 18.0 0.00) (1364.0 26.0 0.00)

Hope it makes sense

 

Cheers

 

0 Likes
Message 13 of 14

Anonymous
Not applicable

make sense.

Regarding the first number, I know -1 stands for entity name, 0 for type, 8 for layer, 62 for color etc.. ; what does -4 here stand for?

Thanks

0 Likes
Message 14 of 14

pbejse
Mentor
Mentor

 

LMGTFY <--- 

0 Likes