Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

SUBTRACTING ".dwg" FROM DWGNAME EXPRESSION 4

Status
Not open for further replies.

DISH

Mechanical
Feb 5, 2003
28
Has anyone found out how to get rid of the extension ".dwg" from the rtext->diesel expresion: $(getvar,"dwgname").
The drawing file name comes out in the drawing but I don't really want to show what file type it is.
Any help out there would be appreciated
 
Replies continue below

Recommended for you

try this

$(substr,$(getvar,"dwgname"),1,$(-,$(strlen,$(getvar,"dwgname")),4))
 
[2thumbsup]

Lothar Win NT4.0 (SP6),
ACAD 2000i (SP2), ADT 3.0 (SP3),
ACAD 2002, ADT 3.3,
OCÈ 5200

 
great thanks that did exactly what i wanted it to do
could you now explain to me how it does this. I am new to diesel expresions and am still learning. Is the 4 in the end to do with flags?
 
DISH,

GETVAR - short for Get Variable
DWGNAME - Variable in AutoCAD which stores the name of the current drawing
STRLEN - Returns the length of the string returned by $(getvar, "dwgname")
SUBSTR - With user specified options, allows for truncating a string at a specified point

To use an example, let's assume you are in a drawing named, 100-03-master.dwg

$(getvar, "dwgname") would return "100-03-master.dwg"

$(strlen,$(getvar,"dwgname")) would return 17 because there are 17 characters in the string which is the drawing name with extension

$(-,$(strlen,$(getvar,"dwgname")),4) would return 13 because I am subtracting 4 from the length of the string.

$(substr,$(getvar,"dwgname"),1,$(-,$(strlen,$(getvar,"dwgname")),4)) returns "100-03-master". The way it does this is as follows:
1. It first gets the drawing name with extension
2. It then gets the length of the drawing name with extension
3. It then returns the length obtained minus 4 because of the 4 characters in ".dwg"
4. Now with the Substr function, it starts at character 1 and goes 13 steps through the string and returns "100-03-master"

The AutoLISP equivalent of this is as follows:
(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))

If you want to store that information to a user specified variable, you might use:
(setq dwg-name (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)))

Hope this helps.
Jeff Foster, PE
CE Group, Inc.
Apex, NC
 
ok, what I need is a diesel expression that can stip out all of the folders except for the last one in the dwgprefix variable. i.e. dwgprefix returns: P:\projects\2003\client\job#\job#.dwg

I want to strip out everything but the job#. This is a little more complicated than mathmatical solutions, since the path length can vary as will all of the lengths of the folder names. The only absolute in every senario is "P:\projects" I can strip it out easy enough. Job#s vary in length as do dwg names. Any suggestions?
 
I kind of knew that would come up. Reason I wanted to use diesel, was to have rtext pull this into the titleblocks in a project. How can I use lisp in a block? I just want the users to insert the titleblock, and have it spit out the project number. Any help would be great!
 

Plight,

Is the project number an attribute in the
titleblock? What's the tagname or attribute
info? What's the name of the titleblock?
Rtext is limited compared to lisp since your
drawing prefix (string length) is varaible.
In RTEXT, theres' no "while" & "repeat" function
which you need in order to extract the job # from
the drawing prefix. It would be nice if an image
of the block showung the attribute is available.
 
Thanks estassoc. The setup is: I have a dwg file that is the titleblock. It consists of the geometry for the border and title areas, attributes to enter the checker's name etc. when it is inserted as a block, text, and rtext to give it a plot stamp, and pull in the date. I currently have an attribute that is the job #. Users edit the attribute to reflect the job #. My goal is to remove this possible area spot, by having the block when it is inserted, add the job# automatically. That is the reason. If the .dwg was named the job #, this wouldn't be an issue, but the file name is that of the client's project number, which I'm already using as an rtext value, so that the client's project # is auto insterted in the block. Due to the # of clients, and their profile, I cannot show their titleblock.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor