Diesel Expression on variable length drawing file names.

Diesel Expression on variable length drawing file names.

dpalmerVQ54W
Enthusiast Enthusiast
935 Views
11 Replies
Message 1 of 12

Diesel Expression on variable length drawing file names.

dpalmerVQ54W
Enthusiast
Enthusiast

Is there a way of using Diesel Expressions to adapt to variable length filenames?

 

My company mainly uses 5 digit project codes, eg 12345. Quite often we have to add a -00X to the project code eg 12345-001.

 

So in the following filename:

12345-ABC-ZZ-03-M2-Y-00001-IPMS3-S3-P01

becomes

12345-001-ABC-ZZ-03-M2-Y-00001-IPMS3-S3-P01

 

When the longer project name is used I lose part of it in my title block, see below:

 

From:

12345.jpg

to

12345-001.jpgI

The PC Project Code in the second image should display 12345-001

and I'm losing 4 characters in the Drawing No.

 

The Diesel expression for the PC Project No. is currently $(substr,$(getvar,dwgname),1,5) this obviously works ok for the 5-character project number but not the 9-character.

 

The Diesel expression for the Drawing No. is currently $(substr,$(getvar,dwgname),1,15) this obviously works ok for the 5-character project number but not the 9-character.

 

I don't want to have create sperate templates for different length project numbers as we have enough already.

 

Thanks in anticipation.

David P
AutoCAD 2021
0 Likes
Accepted solutions (1)
936 Views
11 Replies
Replies (11)
Message 2 of 12

Paul_Gander
Advocate
Advocate

Try this for the Project Number:

$(substr,$(getvar,dwgname),1,$(+,5,$(*,4,$(>,$(strlen,$(getvar,dwgname)),43))))

Change the 5 to 15 for the Drawing Number field.

The macro simply adds 4 to the length of the substring if the drawing name has more than 43 characters (including the .dwg suffix)

0 Likes
Message 3 of 12

paullimapa
Mentor
Mentor

Are you not able to use lisp code because you’re running LT?

Can you share your title block drawing that has the diesel?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 12

dpalmerVQ54W
Enthusiast
Enthusiast

Thanks @Paul_Gander 

 

That worked for the PC Project No field. I tried in the Drawing No. field but I ended up losing other characters. 

Referring back to my screenshots the grey highlight is the part the diesel code is covering.

12345.jpg

I'm trying to minimise the amount of editing required to the drawing number.  This is BSI (British Standards Insitute) numbering. Some elements change, some are fixed. I've just had a thought if it would be better to break the drawing number up using, say a single row table, and use diesel code in each cell?🤔

 

 

@paullimapa I'm using full ACAD 2021 I don't want to have to run a lisp routine to create borders. We have sub-contractors who use our borders, some of whom use LT or other non-ACAD products.

 

Thanks for your help to-date.

 

David P
AutoCAD 2021
0 Likes
Message 5 of 12

Paul_Gander
Advocate
Advocate

@dpalmerVQ54W wrote:

That worked for the PC Project No field. I tried in the Drawing No. field but I ended up losing other characters. 


What characters were missing? Are the filenames not always the same length and format before you insert the additional numerical code?

 

If the length and format varies then it may not be possible to determine if the extra characters have been added.

0 Likes
Message 6 of 12

Kent1Cooper
Consultant
Consultant

@dpalmerVQ54W wrote:

.... I don't want to have to run a lisp routine to create borders. We have sub-contractors who use our borders, some of whom use LT or other non-ACAD products.

....


AutoLisp would be able to look at the first three characters after the first hyphen, and determine whether they are all numerical, in which case it would know the overall string is the longer variety.  I don't see an equivalent are-they-numbers capability in Diesel for LT users.  Even if there is one, can the "other non-ACAD products" use Diesel code?

Kent Cooper, AIA
0 Likes
Message 7 of 12

dpalmerVQ54W
Enthusiast
Enthusiast

12345-001(WITH NEW CODE).jpg@Paul_Gander as you can see in the screenshot I've lost the -ABC-ZZ-03 in the Drawing No.

 

 

 

 

 

 

@Kent1Cooper with regards to your question about non-AutoCAD products using Diesel it does appear to work. I know a couple of our sub-contractors use BricsCAD and the data that comes back from them is fine in terms of using Diesel code.

David P
AutoCAD 2021
0 Likes
Message 8 of 12

paullimapa
Mentor
Mentor

Like @Kent1Cooper the challenge occurs if the file names are not fixed in length, for example, for the shorter project #, will all possible drawing file name lengths always be 39 characters:

12345-ABC-ZZ-03-M2-Y-00001-IPMS3-S3-P01

And then for the longer project #, will all possible drawing file name lengths always be 43=39+4 characters:

12345-001-ABC-ZZ-03-M2-Y-00001-IPMS3-S3-P01

If the answer is no, then there's no way to test when the filename would have the additional project # characters because Diesel does not offer an option to test alpha vs numeric characters.

 So in this case, there's no way to differentiate if there's a "-001" vs "-ABC"

But if you know for certain that the shorter project #s will always have drawing file name lengths of 39 characters, then Diesel can be used to test that and then return project code as just 12345.  But if longer, then return project code as 12345-001


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 12

dpalmerVQ54W
Enthusiast
Enthusiast

I hadn't realised how complex this was going to get! The filename could get longer as one of the options for a filename could be 12345-001-ABC-ZZ-03-M2-Y-00001-IPMS2_TA-S3-P01.

David P
AutoCAD 2021
0 Likes
Message 10 of 12

paullimapa
Mentor
Mentor

Then you’re stuck with having to create sperate templates for different length project numbers. 

Now if you implement  project name variable to store your project number  then Diesel can grab that as your project number in the title block. But implementing that variable will require each drawing when created to run a command to setvar “projectname”. So this is not full proof. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 12

pgander
Explorer
Explorer
Accepted solution

@dpalmerVQ54W wrote:

12345-001(WITH NEW CODE).jpg@Paul_Gander as you can see in the screenshot I've lost the -ABC-ZZ-03 in the Drawing No.

 

 

 

 

 

Did you change the 5 to 15 for the drawing number,  as I suggested in message 2? 

$(substr,$(getvar,dwgname),1,$(+,15,$(*,4,$(>,$(strlen,$(getvar,dwgname)),43))))

 

0 Likes
Message 12 of 12

dpalmerVQ54W
Enthusiast
Enthusiast

Thanks @pgander that seems to have worked. I missed your earlier comment.

David P
AutoCAD 2021
0 Likes