cad diesel表达式实例

I am trying to automate a sheet tag with a Diesel expression in AutoCad.

This gets me the twelfth character in the drawing name. But as soon as I get to sheet 10 this will say its sheet 0.

$(substr,$(getvar,dwgname),12,1)

Does anyone know a way to get an If statement to see if the eleventh character is a 0 then run the above code else run $(substr,$(getvar,dwgname),11,2)

This is something i have tried. $(IF,substr,$(getvar,dwgname),11,1)="0"$(substr,$(getvar,dwgname),11,2,substr,$(getvar,dwgname),12,1)

This appears to be similar to excel formulas. Thanks for any help.

Here is the Diesel expression i got working for auto sheet no. in autocad fields.

$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1))

$(if,$(substr,$(getvar,dwgname),11,1)"0" = Does character 11 = 0 ,$(substr,$(getvar,dwgname),11,2) = if no then take character 11 and the next char. ,$(substr,$(getvar,dwgname),12,1)) = if char 11 is = to 0 then take only char 11.

I use two fields in my autocad border. One for the filename without the sheet no and this one for only the sheet number.

Example filename: A150225_S001.dwg

$(substr,$(getvar,dwgname),1, 7) = Use char from position 1 to 7. "A150225"

$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1)) = Use sheet no. at end of filename string. "1"

Hope this helps anyone looking to do something similar.

To Use DIESEL at the Command Line

you can use DIESEL at the AutoCAD command line by using a command called Modemacro. The Modemacro command sends information to the status bar. Diesel can be used with Modemacro to perform simple tasks. Try the following exercise to experiment with Diesel:

  1. Open a drawing, and then at the Command prompt, type Modemacro↵.
  2. At the Enter new value for MODEMACRO, or . for none <" ">: prompt, enter $(/,25,2)↵. The answer to the equation appears at the left end of the status bar icons.
  3. To clear the status bar, enter Modemacro ↵.
  4. At the Enter new value for MODEMACRO, or . for none <" ">: prompt, enter . (a period). The status will then clear.

The equation you entered in step 2 is referred to as an expression. The structure of DIESEL expressions is similar to that of AutoLISP expressions. The dollar sign tells AutoCAD that the information that follows is a DIESEL expression.

A Diesel expression must include an operator of some sort, followed by the items to be operated on. An operator is an instruction to take a specific action, such as adding two numbers or dividing one number by another. Examples of mathematical operators include the plus sign (+) for addition and the forward slash (/) for division.

The operator is often referred to as a function and the items to be operated on are referred to as the arguments to the function, or simply the arguments. In the expression (/,25,2), the / is the function and 25 and 2 are the arguments. All DIESEL expressions, no matter what size, follow this structure and are enclosed by parentheses. Parentheses are important elements of an expression. All parentheses must be balanced; for each left parenthesis, there must be a right parenthesis.

You can do other things with DIESEL besides performing calculations. The getvar function is an AutoLISP function that you can use to obtain the drawing prefix and name. Try the following to see how DIESEL uses getvar:

  1. Type Modemacro↵ again.
  2. Type $(getvar,dwgprefix)↵. The location of the current drawing appears in the status bar.
  3. Press ↵ to reissue the Modemacro command; then type $(getvar,dwgname)↵. The name of the drawing appears in the status bar.

In this example, the getvar function extracts the drawing prefix and name and displays it in the status bar. You can use getvar to extract any system variable you want. This can be a great tool when you’re creating custom menus because with getvar, you can poll AutoCAD to determine the state of a given system variable. For example, you can find out what command is currently being used. Try the following exercise to see how this works:

  1. Click the Line tool on the Draw panel.
  2. Type ′Modemacro↵. The apostrophe at the beginning of Modemacro lets you use the command while in another command.
  3. Type $(getvar,cmdnames)↵. The word LINE appears in the status bar, indicating that the current command is the Line command.

This information can be useful in building a menu when you want an option to perform a specific task depending on which command is currently active.

Note: Users of AutoCAD LT ® software can’t use AutoLISP to find the location of AutoCAD resource files. However, you can use the DIESEL macro language. For example, to find the log file path, enter Modemacro↵ and then $(getvar,logfilepath). The path is displayed in the status bar. To get the status bar tools back, enter Modemacro↵ and then enter a period.

[]中括号在diesel中的用途介绍

$(+,val1,val2,…valn)

The sum of the numbers val1, val2,…valn is returned.

OR

返回数字 val1val2 、…、 val9 的和。

$(+, val1 [, val2, …, val9])

如果当前厚度被设定为 5,则以下 DIESEL 字符串返回 15。

$(+, $(getvar, thickness), 10)

晓东论坛还有一篇文章:

http://bbs.xdcad.net/thread-670095-1-1.html

参考一下。

Field in Field using Diesel

I've placed this in the AC2008 forum, maybe this is a better place for it.

The problem I'm having is:
I've got an attributed block, which I want to link (using a field) to a MText object. Now that's fine in theory, but the attribute now also shows all the control codes in the MText, e.g. \p for returns. I thought I could try removing them using the Diesel string manipulator functions, but no cigar.

Here's what I tried:
1. Create the field link to the MText's contents.
2. Select & copy the field code listed at the bottom of the dialog.
3. Change the field to Other/Diesel Expression.
4. Use say the $(substr, method, pasting the previous field code as the source string.

This works fine, until you click the OK button. The field appears correct, but won't update if the MText is changed. So I went back to the field dialog and saw that the "field within field" has disappeared. Only the original text of the MText is shown where I pasted the field code in step 4 above.

Does anyone know if I did something wrong, or if there's a better or easier way, or even just one that works.

The method above works when using formulas in fields, but seems to not work for Diesel expressions. I've noticed that when using this firld inside a field in formulas, the code is changed to a field pointer (%<\_FldPtr 1885652536>%) instead of the usual %<\AcObjProp Object(%<\_ObjId 1913540096>%).....>%. I tried copying this to a diesel as well, but then it doesn't work at all.

猜你喜欢

转载自blog.csdn.net/pilifeng1/article/details/89365921
CAD
今日推荐