Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
michael.deleurere
Posts: 40
Registered: ‎09-19-2011
Message 1 of 16 (614 Views)
Accepted Solution

ssget by coordinates

614 Views, 15 Replies
02-07-2013 09:05 AM

i am working on writing a lisp to update several similar drawings through a .bat file.  One of the things i would like to do is to automtaically increase the revision number by one.  I have figured out everything except how to select the text.  Looking at the database, the coordinates for the revision number are (10 15.2908 0.0295 0.0).  However, (setq a (ssget "x" '((0 . "TEXT,MTEXT")(10 15.2908 0.0295 0.0)))) returns nil. 

 

Are the database coordinate values not precice enough?  If so, how can I determine what the actual coordinatea are?

 

If each drawing's revision number is not in the exact same location, is it possible to select by a range of coordinates?  Using (getpoint), the range is from (15.5 0.0 0.0) to (15.1805 0.1409 0.0).

Mentor
southie
Posts: 291
Registered: ‎03-15-2007
Message 2 of 16 (600 Views)

Re: ssget by coordinates

02-07-2013 11:26 AM in reply to: michael.deleurere

Assuming that there is only one element to your selection set this might get you started.

 

(setq cnt 1)

(setq ss1 (ssget "c" '(15.5 0.0) '(15.1805 0.1409)))

(setq ent1 (entget (ssname ss1 0))

         revno (cdr (assoc 1 ent1))  

 

    (setq new (cons 1 (itoa (+ (atoi revno) cnt)))  

            old (assoc 1 ent1)      

            ent1 (subst new old ent1))

         (entmod ent1) 

 

southie

Mentor
southie
Posts: 291
Registered: ‎03-15-2007
Message 3 of 16 (597 Views)

Re: ssget by coordinates

02-07-2013 11:29 AM in reply to: southie

oops should have been

 

(setq cnt 1)

(setq ss1 (ssget "c" '(15.5 0.0) '(15.1805 0.1409)))

(setq ent1 (entget (ssname ss1 0))

         revno (cdr (assoc 1 ent1)) 

 

    (setq new (cons 1 (itoa (+ (atoi revno) cnt))) 

            old (assoc 1 ent1)     

           ent77 (subst new old ent1))

         (entmod ent77)

Mentor
southie
Posts: 291
Registered: ‎03-15-2007
Message 4 of 16 (587 Views)

Re: ssget by coordinates

02-07-2013 11:41 AM in reply to: michael.deleurere

Very fat fingured today.

 

should have been

 

(setq cnt 1)

(setq ss1 (ssget "c" '(15.5 0.0) '(15.1805 0.1409)))

(setq ent1 (entget (ssname ss1 0))

         revno (cdr (assoc 1 ent1))

);setq

 

    (setq new (cons 1 (itoa (+ (atoi revno) cnt)))

            old (assoc 1 ent1)    

           ent77 (subst new old ent1))

         (entmod ent77)

Active Contributor
michael.deleurere
Posts: 40
Registered: ‎09-19-2011
Message 5 of 16 (580 Views)

Re: ssget by coordinates

02-07-2013 11:51 AM in reply to: southie

southie wrote:

Very fat fingured today.

 

should have been

 

(setq cnt 1)

(setq ss1 (ssget "c" '(15.5 0.0) '(15.1805 0.1409)))

(setq ent1 (entget (ssname ss1 0))

         revno (cdr (assoc 1 ent1))

);setq

 

    (setq new (cons 1 (itoa (+ (atoi revno) cnt)))

            old (assoc 1 ent1)    

           ent77 (subst new old ent1))

         (entmod ent77)


(setq ss1 (ssget "c" '(15.5 0.0) '(15.1805 0.1409)))

(setq ent1 (entget (ssname ss1 0)))

        (setq revno (cdr (assoc 1 ent1)))

 

    (setq new (cons 1 (itoa (+ (atoi revno) cnt))))

            (setq old (assoc 1 ent1)     )

           (setq ent77 (subst new old ent1))

         (entmod ent77)

 

very nice, thanks.  much more simple than the way i wrote it:

 

(setq a (ssget "c" '(15.5 0.0) '(15.1805 0.1409)))

(setq b (cdr (assoc 1 a)))
(setq c (atoi b))
(setq d (+ 1 c))
(setq e (itoa d))

(setq a (subst (cons 1 e) (assoc 1 a) a))

(entmod a)

*Expert Elite*
Kent1Cooper
Posts: 5,408
Registered: ‎09-13-2004
Message 6 of 16 (569 Views)

Re: ssget by coordinates

02-07-2013 01:44 PM in reply to: michael.deleurere

michael.deleurere wrote:
....

(setq ss1 (ssget "c" '(15.5 0.0) '(15.1805 0.1409)))

....


You might consider a little adjustment.  Because not all numbers "touch" their insertion points, that way of looking for them might miss them sometimes.  In the left-justified situation in the attached image,

 

(ssget "C" '(0 0 0) '(1 1 0))

 

returns nil, though the insertion point is right in the middle of the window it's looking at.  The possibility of any problem will vary with size of your positional range in relation to the text size, and/or with the justification and the text characters involved, but given the "wrong" relationship, you could have the same happen with, say, a middle-justified 11, etc., etc.

 

You could either use a larger Crossing window, as long as you limit its size to eliminate the risk of catching some unwanted object(s) in addition to the desired one, such as Line parts of a title block.  Or you could determine the coordinates of a [non-crossing] Window that will always include the whole number, its size depending on how many characters it's ever likely to reach.

Kent Cooper
Mentor
stevor
Posts: 850
Registered: ‎12-26-2005
Message 7 of 16 (552 Views)

Re: ssget by coordinates

02-07-2013 06:31 PM in reply to: michael.deleurere
And you may have to zoom to the coordinates, or a zoom all.
S
*Expert Elite*
pbejse
Posts: 2,460
Registered: ‎11-24-2009
Message 8 of 16 (540 Views)

Re: ssget by coordinates

02-07-2013 09:48 PM in reply to: michael.deleurere

michael.deleurere wrote:

(setq ss1 (ssget "c" '(15.5 0.0) '(15.1805 0.1409)))

(setq ent1 (entget (ssname ss1 0)))

        (setq revno (cdr (assoc 1 ent1)))

 

    (setq new (cons 1 (itoa (+ (atoi revno) cnt))))

            (setq old (assoc 1 ent1)     )

           (setq ent77 (subst new old ent1))

         (entmod ent77)

 


I guess you dont  realize you can add a filter with (ssget  "C" ...)

 

(setq ss1 (ssget "c" '(15.5 0.0) '(15.1805 0.1409)'((0 . "TEXT,MTEXT")(1 . "#*")))) 

 

you can even throw in a layer/height/color etc.... that way you can increase the size of the window without  the risk of catching some unwanted object(s)

 

HTH

 

*Expert Elite*
pbejse
Posts: 2,460
Registered: ‎11-24-2009
Message 9 of 16 (533 Views)

Re: ssget by coordinates

02-07-2013 11:07 PM in reply to: stevor

stevor wrote:
And you may have to zoom to the coordinates, or a zoom all.

Hang on, stevo raised a good point there. 

 

perhaps we can still use ssget "X"

 

(setq ss1 (ssget "_X" '((0 . "TEXT,MTEXT")(1 . "#*")
		       (-4 . "<AND")
		       (-4 . ">=,<=,*")(10 15.1805 0.1409 0.0)
		       (-4 . "<=,>=,*")(10 15.5 0.0 0.0)
		       (-4 . "AND>"))))

 

You may need to add DXF 410 in there  

 

HTH

 

Active Contributor
michael.deleurere
Posts: 40
Registered: ‎09-19-2011
Message 10 of 16 (521 Views)

Re: ssget by coordinates

02-08-2013 05:56 AM in reply to: pbejse

so far, i am still testing on the first drawing and

 

(setq ss1 (ssget "c" '(15.5 0.0) '(15.1805 0.1409)))

 

works fine.  those coordinates represent the box on the border in which the revision number lies.  Once testing begins on a series of drawings, it may have to be further refined.

 

one other issue i have run into:  apart from chaning the revision number, there is also a place for a revision number/ description on the title block.  i have created a seperate drawing with the revision description which will insert as a block to specific coordinates based on the newly changed number from this:

 

(setq new (cons 1 (itoa (+ (atoi revno) cnt))))

 

the revision description block drawing shows a revision number of 0, which will then get added to by (setq cnt #)

 

using the original code, i have set up a conditional statement as follows:

 

 

(cond
 ((= new 2)
  (command "-insert" "revd.dwg" "8.9076,0.2496" "1" "1" "0")
         (command "explode" "last")
         (command "-purge" "block" "rev" "n")
  (setq cnt 2)
  (setq ss1 (ssget "c" '(8.9076 0.624) '(9.188 0.4992)))
  (setq ent1 (entget (ssname ss1 0)))
  (setq revno (cdr (assoc 1 ent1)))
  (setq new (cons 1 (itoa (+ (atoi revno) cnt))))
  (setq old (assoc 1 ent1))
  (setq ent77 (subst new old ent1))
  (entmod ent77)
 );end condition

 

 ((= new 3)
  (command "-insert" "rev.dwg" "8.9076,0.3744" "1" "1" "0")
         (command "explode" "last")
         (command "-purge" "block" "rev" "n")
  (setq cnt 3)
  (setq ss1 (ssget "c" '(8.9076 0.4992) '(9.188 0.3744)))
  (setq ent1 (entget (ssname ss1 0)))
  (setq revno (cdr (assoc 1 ent1)))
  (setq new (cons 1 (itoa (+ (atoi revno) cnt))))
  (setq old (assoc 1 ent1))
  (setq ent77 (subst new old ent1))
  (entmod ent77) 
 );end condition
);end cond.

 

however, both of these return nil.  i have also tried ((= new "3")... but that returns also returns nil. 

 

since running the statement without conditionals works fine, the problem is the cond statment is not reading the value of "new".   how can i get the conditional to recognize the new revision number? 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.