Extracting filename to field for titleblock

Extracting filename to field for titleblock

JohnMartin6269
Contributor Contributor
1,964 Views
15 Replies
Message 1 of 16

Extracting filename to field for titleblock

JohnMartin6269
Contributor
Contributor

Hello all,

 

I am looking for a way to extract a portion of the full filename of my drawings to a field for my titleblock on drawings. I can use DIESEL to extract part of it but am trying to figure out how to extract a portion of the filename UP TO BUT NOT INCLUDING the first space in the name. Example file names are as follows:

 

LUIB_A-101 FIRST FLOOR PLAN

LUIB_S-101A STRUCTURAL FLOOR PLAN AREA 1

 

What I want to extract is the bold/italic portion of the file name, but this portion is not consistent in length. I am not sure how to accomplish this and would love some guidance on this issue. If they were the same length every time a simple DIESEL expression would work well, but the change in total characters is throwing me for a loop.

 

Thanks in advance.

0 Likes
1,965 Views
15 Replies
Replies (15)
Message 2 of 16

ronjonp
Advisor
Advisor

Not a field but this is a very easy task in lisp:

(if (setq i (vl-string-search " " (setq str "LUIB_S-101A STRUCTURAL FLOOR PLAN AREA 1")))
  (substr str (+ 2 i))
)
0 Likes
Message 3 of 16

ronjonp
Advisor
Advisor

I guess you could do something like this too:

;; Add this to your startup
(defun makeglobal (/ a i)
  (setq a (getvar 'dwgname))
  (setq	*mydrawingvariable*
	 (if (setq i (vl-string-search " " a))
	   (substr a (+ 2 i))
	   a
	 )
  )
  (princ)
)
(makeglobal)
;; Then add this field to your drawing where needed
;; %<\AcVar.17.0 Lisp.*mydrawingvariable*>%
0 Likes
Message 4 of 16

JohnMartin6269
Contributor
Contributor

Now how do I use this to add the information into the titleblock if it's not a field?  I need the filename string to read this and aoutmatically fill out BEFORE I plot the drawings. I am horrible at LISP hence the reason i am asking.

 

John

0 Likes
Message 5 of 16

ronjonp
Advisor
Advisor

Post a sample DWG of your titleblock and I'll put something together.

0 Likes
Message 6 of 16

JohnMartin6269
Contributor
Contributor

Here is the titleblock.

0 Likes
Message 7 of 16

JohnMartin6269
Contributor
Contributor

Here is the titleblock.

0 Likes
Message 8 of 16

ronjonp
Advisor
Advisor

Here is what I meant, all you have to do is run the code below then regen .. I was envisioning your titleblock having attributes so the name could be populated easily. Since it's just text it makes it a bit harder. Do you XREF this into your plans?

(defun c:foo (/ a i)
  (setq a (getvar 'dwgname))
  (setq	*mydrawingvariable*
	 (if (setq i (vl-string-search " " a))
	   (substr a (+ 2 i))
	   a
	 )
  )
  (princ)
)
0 Likes
Message 9 of 16

JohnMartin6269
Contributor
Contributor

yes, we XREF the TB into our sheets.  I'll give that a shot and see what happens. Thanks for the help thus far.

0 Likes
Message 10 of 16

JohnMartin6269
Contributor
Contributor

Well it seems to be pulling in everything AFTER the space. I'm after the stuff before the space with no file extension.

0 Likes
Message 11 of 16

ronjonp
Advisor
Advisor

Reading your first post a bit closer the code I provided above does the opposite you're asking for ( I think ).

This will extract the beginning of the filename up to the space.

(defun c:foo (/ a i)
  (setq a (getvar 'dwgname))
  (setq	*mydrawingvariable*
	 (if (setq i (vl-string-search " " a))
	   (substr a 1 i)
	   a
	 )
  )
  (princ)
)
0 Likes
Message 12 of 16

JohnMartin6269
Contributor
Contributor

And finally, do I add the

 

%<\AcVar.17.0 Lisp.*mydrawingvariable*>% 

as a field in the titleblock? Going into fields I do not see a place to add that variable.

0 Likes
Message 13 of 16

ronjonp
Advisor
Advisor

Since your titleblock is referenced, yes add the field code into it. You will only see the option in the field command AFTER you run the code and the global variable is created.

 

What is the range of length for this text string you're trying to get?

 

If this is the number of your sheet and you use paperspace, I'd name the tab accordingly then use the field code: %<\AcVar ctab>%

 

0 Likes
Message 14 of 16

JohnMartin6269
Contributor
Contributor

It's a maximum of 10 characters.

0 Likes
Message 15 of 16

ronjonp
Advisor
Advisor

And the minimum?

0 Likes
Message 16 of 16

ronjonp
Advisor
Advisor

Well I've wanted to mess around with diesel so here's something that will grab the first part of a filename if a space is found in 11th or 12th digit. It does not seem to work nesting past one though.

 

For legibility line by line:

$(if,$(EQ,$(substr,$(getvar,dwgname),11,1)," "),$(substr,$(getvar,dwgname),1,10),no)
$(if,$(EQ,$(substr,$(getvar,dwgname),12,1)," "),$(substr,$(getvar,dwgname),1,11),$(getvar,dwgname))

This nesting works:

$(if,$(eq,$(substr,$(getvar,dwgname) ,11,1) , " ")
      ,$(substr,$(getvar,dwgname) ,1,10)
      ,$(if,$(eq,$(substr,$(getvar,dwgname) ,12,1) , " ")
	    ,$(substr,$(getvar,dwgname) ,1,11)
	    ,$(getvar,dwgname)
      )
)

Multiple nested does not work .. probably some limitation me thinks.

$(if,$(eq,$(substr,$(getvar,dwgname) ,9,1) , " ")
      ,$(substr,$(getvar,dwgname) ,1,8)
      ,$(if,$(eq,$(substr,$(getvar,dwgname) ,10,1) , " ")
	    ,$(substr,$(getvar,dwgname) ,1,9)
	    ,$(if,$(eq,$(substr,$(getvar,dwgname) ,11,1) , " ")
		  ,$(substr,$(getvar,dwgname) ,1,10)
		  ,$(if,$(eq,$(substr,$(getvar,dwgname) ,12,1) , " ")
			,$(substr,$(getvar,dwgname) ,1,11)
			,$(getvar,dwgname)
		  )
	    )
      )
)

 

 

0 Likes