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

ssget by coordinates

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
m.deleurere
3392 Views, 15 Replies

ssget by coordinates

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).

15 REPLIES 15
Message 2 of 16
southie
in reply to: m.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

Message 3 of 16
southie
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)

Message 4 of 16
southie
in reply to: m.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)

Message 5 of 16
m.deleurere
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)

Message 6 of 16
Kent1Cooper
in reply to: m.deleurere


@Anonymous.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, AIA
Message 7 of 16
stevor
in reply to: m.deleurere

And you may have to zoom to the coordinates, or a zoom all.
S
Message 8 of 16
pbejse
in reply to: m.deleurere


@Anonymous.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

 

Message 9 of 16
pbejse
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

 

Message 10 of 16
m.deleurere
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? 

Message 11 of 16
pbejse
in reply to: m.deleurere


@Anonymous.deleurere wrote:

 

 

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:

 


Question for you: instead of  "inserting" and "exploding", why not just create new entities with a given set of properties?

 


@Anonymous.deleurere wrote:

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

 


We understand that michael. but eventually you will encounter the condition that stevo mentioned on his post. So based on your OP you''ll  be better of using ssget "X" . especially if you're planning to use the program via scipt on multiple drawings.

 

HTH

Message 12 of 16
m.deleurere
in reply to: pbejse


@pbejse wrote:

Question for you: instead of  "inserting" and "exploding", why not just create new entities with a given set of properties?

 

 


We understand that michael. but eventually you will encounter the condition that stevo mentioned on his post. So based on your OP you''ll  be better of using ssget "X" . especially if you're planning to use the program via scipt on multiple drawings.

 

HTH


the ssget "x" certainly works better as sometimes a line or polyline was being selected. 

 

the test drawing is currently revision 2.  when running:

 

(setq cnt 1)
(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>"))))
(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)

 

the revision number changes to 3 and the variable NEW is set to "3".  however, the conditional statement:

 

(cond
 ((= new "2")
  (command "-insert" "rev.dwg" "8.9076,0.2496" "1" "1" "0")
   (command "explode" "last")
   (command "-purge" "block" "rev" "n")
  (setq cnt 2)
  (setq ss1 (ssget "_X" '((0 . "TEXT,MTEXT")(1 . "#*")(-4 . "<AND")(-4 . ">=,<=,*")
   (10 8.9076 0.624 0.0)(-4 . "<=,>=,*")(10 9.188 0.4992 0.0)(-4 . "AND>"))))

  (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 "_X" '((0 . "TEXT,MTEXT")(1 . "#*")(-4 . "<AND")(-4 . ">=,<=,*")
   (10 8.9076 0.4992 0.0)(-4 . "<=,>=,*")(10 9.188 0.3744 0.0)(-4 . "AND>"))))
  (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

 

returns nil.  any ideas why the cond statement does not recognize the variable NEW being equal to 3?

 

i did not think about simply creating the text in the revision description as opposed to inserting a block.   either way i am going to have to reference the revision number from the variable NEW.

Message 13 of 16
m.deleurere
in reply to: m.deleurere

for reasons unknown, creating a different variable equal to NEW and running ithat through the cond statement did the trick:

 

(setq num (cdr new))

 

(cond ((= num "2")....

 

thanks again to all for your help.

Message 14 of 16
pbejse
in reply to: m.deleurere

I think you're going about it the wrong way michael.

 

The condition expression on your code is bloated with repeated functions:

 

Tell us what does the "rev.dwg" block looks like? 

 

If you dont mind posting the entire code so us here can suggest an alternative.

 

Message 15 of 16
m.deleurere
in reply to: pbejse

Spoiler
 

the source rev block is text that is used for the revision description in the title block, which also contains a revision number.  in the source description block, the revision number is 0.  the conditional statement is a way to insert the description on the correct line of the title block and to match the revision number in the lower right corner of the drawing to the revision number in the description by adding the new revision number to 0.  here is the full code:

 

(defun C:REVN(/ OM CNT SS1 ENT1 REVNO NEW OLD ENT77 NUM )

(setvar "cmdecho" 0)
(setvar "filedia" 0)
(setq OM (getvar "osmode"))
(setvar "osmode" 0)
(command "zoom" "extents")

 

;add 1 to existing revision number in lower right corner:

(setq cnt 1)
(setq ss1 (ssget "_X" '((0 . "TEXT,MTEXT")(-4 . "<or")(1 . " #*")(1 . "#*")(-4 . "or>") (-4 . "<and") (-4 . ">=,<=,*")
 (10 15.1805 0.1409 0.0) (-4 . "<=,>=,*")(10 15.5 0.0 0.0) (-4 . "AND>"))))
(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)
(setq num (cdr new))

 

;insert revision description, match revision numbers:

(cond
 ((= num "2")
  (command "-insert" "rev.dwg" "8.9076,0.2496" "1" "1" "0")
         (command "explode" "last")
         (command "-purge" "block" "rev" "n")
  (setq cnt 2)
  (setq ss1 (ssget "_X" '((0 . "TEXT,MTEXT")(1 . "#*")(-4 . "<AND")(-4 . ">=,<=,*")
   (10 8.9076 0.624 0.0)(-4 . "<=,>=,*")(10 9.188 0.4992 0.0)(-4 . "AND>"))))
  (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

 ((= num "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 "_X" '((0 . "TEXT,MTEXT")(1 . "#*")(-4 . "<AND")(-4 . ">=,<=,*")
   (10 8.9076 0.4992 0.0)(-4 . "<=,>=,*")(10 9.188 0.3744 0.0)(-4 . "AND>"))))
  (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

 

(setvar "cmdecho" 1)
(setvar "filedia" 1)
(setvar "osmode" OM)
(command "QUIT" "Y")

(princ)

)

 

 

 

Message 16 of 16
pbejse
in reply to: m.deleurere

something odd about the way you select the inserted block,

 

@ value 3 the insertion point is 0.1248 units higher than block for value 2, but the window selection for value 3 is going the other way (donwards).. which way is it?

 

BTW: if the rev.dwg block only has one entity [text entity] . you dont need to use ssget filter to capture the "last" entity for modification and just use (entlast) after explode or better yet create the "TEXT" on the fly using entmakex with

specific properties as agruments.

 

What you need to do the math is the insertion point of the text, or in this case the block.

 

(defun C:REVN(/ _repeatedfunction ss1 rev_num next_point)
(setvar "cmdecho" 0)
(setvar "filedia" 0)
(setq OM (getvar "osmode"))
(setvar "osmode" 0)
(command "zoom" "extents")

(defun _repeatedfunction  (e cnt / nt1 revno new old ent77)
	   (setq ent1 (entget e))
           (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)
           (cdr new)
  )
(if   (and (findfile "rev.dwg")
  	(setq ss1 (ssget "_X"
                         '((0 . "TEXT,MTEXT")  (-4 . "<or")
                           (1 . " #*") (1 . "#*")  (-4 . "or>")
                           (-4 . "<and") (-4 . ">=,<=,*")
                           (10 15.1805 0.1409 0.0)  (-4 . "<=,>=,*")
                           (10 15.5 0.0 0.0) (-4 . "AND>"))))
) (progn (setq rev_num (_repeatedfunction (ssname ss1 0) 1)) (setq next_point (list 8.9076 (* (atoi rev_num) 0.1248))) (command "-insert" "*rev.dwg" "_non" next_point "1" "0") (_repeatedfunction (entlast) (atoi rev_num)) ) ) (setvar "cmdecho" 1) (setvar "filedia" 1) (setvar "osmode" OM) ;(command "QUIT" "Y") (princ) )

 

If you're interested I can show you how to use entmakex instead 

 

HTH

 

Cheers

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

Post to forums  

Autodesk Design & Make Report

”Boost