Auto Number Block Page Number

Auto Number Block Page Number

LoganAC34
Advocate Advocate
2,426 Views
13 Replies
Message 1 of 14

Auto Number Block Page Number

LoganAC34
Advocate
Advocate

Currently the way my company drafts is purely in model space. We have an elevation block that we place in plan and elevation views and then change two attributes, elevation letter and page number. It gets really tedious changing all the page numbers on all the elevation markers since you sometimes have 3 for each elevation (one on plan view, one or adjacent elevations).


This might be tricky, but my idea is to have a lisp that changes the page number attribute on the elevation marker to the page number the elevation tag is on, which isn't in the same page most of the time.


There are four different blocks that this lisp would reference; Elevation marker, elevation tag, elevation tag AA-ZZ, and title block. If possible i would like to also reference a specific style of text.


The way i'm thinking lisp would work is it would prompt the user to select all of the title blocks containing the plan and elevation views. The lisp would then look for all of the elevation tags (and specific style of text) and keep a list of what elevation letter is on what title block page number. It would then search for the corresponding elevation marker and change the page number attribute to match the corresponding title block page number that the elevation tag is on.


The requirements for the lisp to work properly would be that every elevation tag and marker has to be placed and have the correct elevation letter typed in, they would all have to be placed in title blocks, and all the title blocks have to be numbered. A few problems I see with this that could mess it up is if there are two of the same elevation tags, there are no elevation markers to match to a elevation tag or two title blocks with the same page number. For this i would just like an error message saying something like 'there are duplicate page number(s)/elevation letter(s)', and if its not too much to ask to list the page numbers or elevation letters. A few other problems i see with coding is we scale up or down our title blocks to fit the content that is inside, just being able to identify what title block the elevation tag is on, and identifying what is an elevation letter since it could be just text with some custom elevation letter like 1.A or AB.1, or 1A, etc.

 

I've attached a file that has the blocks and text and an expample. Thanks.

0 Likes
Accepted solutions (1)
2,427 Views
13 Replies
Replies (13)
Message 2 of 14

pbejse
Mentor
Mentor

@LoganAC34 wrote:

 

......

The way i'm thinking lisp would work is it would prompt the user to select all of the title block......  letter like 1.A or AB.1, or 1A, etc.

 

I've attached a file that has the blocks and text and an expample. Thanks.


 

Not sure I completely understand the requirement. I can't tell the difference between the top [ This ] and the one at the bottom [ the other this ] or is it just me?

 

 

 

 

 

0 Likes
Message 3 of 14

LoganAC34
Advocate
Advocate

Woops. The elevation markers in the first "this" is supposed to have pound signs in "Elevation_Pg_no." attribute.

0 Likes
Message 4 of 14

maratovich
Advisor
Advisor

I do not understand this example.
Can you make only two - one title block as is, and another as needed.
Show arrows what and where should be written.

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 5 of 14

LoganAC34
Advocate
Advocate

The best example would be 6 title blocks (3 on top, 3 on bottom) since it has to do with the page numbering. Attached is a new file that show arrows describing what should happen. Sorry for the confusion. Basically the whole idea of the lisp is to auto number the elevation marker with the proper page number.

0 Likes
Message 6 of 14

pbejse
Mentor
Mentor

Why is it that the title blocks are numbered "01" "02" "03" but Elevation markers are "1" "2" "3"

Tell us now If you're planning to change the TEXT elevation tag to a block before I post the code.

< excluding TEXT elevation tag >

 

https://autode.sk/2xaAa3O <--- look here

 

 

0 Likes
Message 7 of 14

LoganAC34
Advocate
Advocate

@pbejse wrote:

Why is it that the title blocks are numbered "01" "02" "03" but Elevation markers are "1" "2" "3"

Tell us now If you're planning to change the TEXT elevation tag to a block before I post the code.

< excluding TEXT elevation tag >

 

https://autode.sk/2xaAa3O <--- look here

 

 


Its just how my company does it. Once the page numbers get to 10 they stop having "0" before them ("09", "10", "11"). Ideally I would like to have the elevation markers not have the "0" before the number, so just "1" "2" "3".

I'm not planning to change the text elevation tag to a block. Its text as a result of needing a custom elevation tag (other than A-Z or AA-ZZ) and exploding one of the other two elevation tag blocks to make it. Thanks.

0 Likes
Message 8 of 14

pbejse
Mentor
Mentor
Accepted solution
 

@LoganAC34 wrote:Its just how my company does it. Once the page numbers get to 10 they stop having "0" before them ("09", "10", "11"). Ideally I would like to have the elevation markers not have the "0" before the number, so just "1" "2" "3"

 

Try this

(defun c:ANBPN	 (/ _AttFunc _DPfunc  data     _remspace
                   Tblock   emarker  eTag     ss       i
                   e        efname   bp       f        at_TB
                   a        TagIsInsde        eString
                  )

;;;					pBe Sep 2018					;;;
;;;			Auto Number Block Page Number  			;;;
  
(defun _AttFunc (en / a v)
  (mapcar (function
            (lambda (at)
              (list (vla-get-tagstring at) (vla-get-textstring at) at))
              
            )
          (vlax-invoke en 'Getattributes)
  )
)
(Defun _DPfunc (en nm)
  	(vl-some '(lambda (d)
                 (if (eq (vlax-get d 'PropertyName) nm) (vlax-get d 'Value)))
					(Vlax-invoke en 'GetDynamicBlockProperties)
              )
  )
(defun _remspace (str)
  	(foreach func '(vl-string-right-trim vl-string-left-trim)
       	(setq str ((Eval func)  " " str)))
  )
	

(setq data '( "ELEVATION MARKER" "TITLE BLOCK" "ELEVATION TAG AA-ZZ" "ELEVATION TAG"))
  (if
    (setq Tblock nil emarker nil  eTag nil TagIsInsde nil
		ss (ssget (list
						'(-4 . "<OR")
						'(-4 . "<AND")
                              '(0 . "INSERT") (cons 2  (apply 'strcat 
					    						(mapcar '(lambda (a)(strcat   a "," ))
					                                      (cons "`*U*" data))))
                              '(-4 . "AND>")
                              '(-4 . "<AND")
                              '(0 . "TEXT")'(1 . "%%U Elevation *")'(8 . "TITLES")                              
	 					'(-4 . "AND>")
	 					'(-4 . "OR>")
                              )
                    )
          )
    (progn
	      (repeat (setq i (sslength ss))
			(setq e (vlax-ename->vla-object (ssname ss (Setq i (1- i)))))			
	        		
				(Cond
						(	(eq  (vla-get-objectname e) "AcDbText")
                               		(setq eString (Vla-get-textstring e))
                               		(setq p (vl-string-search "Elevation " eString ))
                               			(setq eTag (Cons  (list
                                                                 (_remspace (substr eString  (+ 10 p))) e) eTag))
                               				)
                      		(	(eq (car data) (setq efname  (strcase (vla-get-effectivename e))))
                                			(setq att_data (_AttFunc e ))
			                           		(setq emarker (Cons
			                                                      (list (cadr (assoc "ELEVATION_LETTER." att_data))
                                                                           (caddr (assoc "ELEVATION_PAGE_NO." att_data)))	
                                                                            emarker))
			                            		)
			        		 (	(eq (cadr data) efname)(vla-GetBoundingBox e 'll 'ur)
			                           		(setq Tblock (Cons
			                                                      (list (cadr
                                                                             (assoc "SHT-NO." (_AttFunc e )))
			                                                            (mapcar 'vlax-safearray->list (list ll ur))) Tblock))
			                            		)
						 (	(member  efname (cddr data))
	                           			(if (setq v (_DPfunc e "Elevation"))
			                           		(setq eTag (Cons  (list v e) eTag)))
	                           				)
	                 )
	        )
      	(if
            (and emarker Tblock efname
                 	(foreach tag eTag
                      	(Setq bp (vlax-get (cadr tag) 'Insertionpoint))
                 		(if (setq f  (vl-some '(lambda (tb)
								(setq l (caadr tb) u (cadadr tb))
									(if (and (< (car l)  (Car bp)  (car u))
										    (< (cadr l) (Cadr bp) (cadr u))) (Car tb)))	
															Tblock))
                           	(setq TagIsInsde (cons
                                                 (cons (car tag) f) TagIsInsde))
                           )
                      TagIsInsde
                      )
                 )
            
                 	(while (setq a (Car emarker))
                      (if (setq at_TB (Cdr (assoc (car a) TagIsInsde)))
                        (vla-put-textstring (cadr a) (itoa (Atoi at_TB)))
                      )
                      (setq emarker (Cdr emarker))
                    )
                 )
			)
		    )
		(princ)
		  )

HTH

 

 

0 Likes
Message 9 of 14

LoganAC34
Advocate
Advocate

It works pretty good, thanks! Would it be too hard to have it work with the elevation tag text? Other than that it works perfectly.

0 Likes
Message 10 of 14

pbejse
Mentor
Mentor

 


@LoganAC34 wrote:

Would it be too hard to have it work with the elevation tag text?

 

Not sure I understand.

This bit right here takes care of the elevation tag text

 

 

....
'(0 . "TEXT")'(1 . "%%U Elevation *")'(8 . "TITLES")  
....
(	(eq  (vla-get-objectname e) "AcDbText")
                               		(setq eString (Vla-get-textstring e))
                               		(setq p (vl-string-search "Elevation " eString ))
                               			(setq eTag (Cons  (list
                                                                 (_remspace (substr eString  (+ 10 p))) e) eTag))
                               				)
...

 

The program works on the posted sample drawing file.

Not unless there's a change in the TEXT/String property then it wouldn't work as expected

The code's selection filter is expecting to find the string value of "%%U Elevation *" on a TEXT entity that's on "TITLES" layer.

 

We can change the filter to something else, show us another example where the routine ignored the text elevation tag.

 

Please Don't keep us guessing here 🙂

 

 

 

 

 

 

0 Likes
Message 11 of 14

LoganAC34
Advocate
Advocate

It actually works with the text, i'm just an idiot. I just forgot to switch the text to the "Titles" layer after I exploded the tag block... I'll mark this posts as solved. Thank you so much, this will save a lot of time in the future.

0 Likes
Message 12 of 14

LoganAC34
Advocate
Advocate

I know its been a while since you solved post, but do you mind adding comments to your code? Don't worry about it if it will take too long. I'm just trying to learn from it to so I can write a similar LISP for another idea I have. You don't need to put a comment for every line, just the start of each main function and sub functions. The one i'm mainly interested in is how you can figure out that an object is inside of a title block and get that title blocks page number. Thanks.

0 Likes
Message 13 of 14

maratovich
Advisor
Advisor

Do you want to number the title blocks?

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 14 of 14

LoganAC34
Advocate
Advocate

No. The original issue in this thread has been solved. The other issue I have is simple enough that I want to try to tackle it myself. I just need help understanding how pbejse's code works. I probably should have just direct messaged them. Thanks though.

0 Likes