Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 11 of 16 (239 Views)

Re: ssget by coordinates

02-08-2013 07:19 AM in reply to: michael.deleurere

michael.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?

 


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

Active Contributor
michael.deleurere
Posts: 37
Registered: ‎09-19-2011
Message 12 of 16 (236 Views)

Re: ssget by coordinates

02-08-2013 07:55 AM 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.

Active Contributor
michael.deleurere
Posts: 37
Registered: ‎09-19-2011
Message 13 of 16 (234 Views)

Re: ssget by coordinates

02-08-2013 08:26 AM in reply to: michael.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.

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 14 of 16 (222 Views)

Re: ssget by coordinates

02-09-2013 03:57 AM in reply to: michael.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.

 

Active Contributor
michael.deleurere
Posts: 37
Registered: ‎09-19-2011
Message 15 of 16 (206 Views)

Re: ssget by coordinates

02-11-2013 06:47 AM 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)

)

 

 

 

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

Re: ssget by coordinates

02-11-2013 11:24 PM in reply to: michael.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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community