caddiel表达式实例
I am trying to automate a sheet tag with a Diel 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 e if the eleventh character is a 0 then run the above code el 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 Diel 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 u 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) = U char from position 1 to 7. "A150225"
$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1)) = U sheet no. at end of filename string. "1"
Hope this helps anyone looking to do something similar.
To U DIESEL at the Command Line
you can u DIESEL at the AutoCAD command line by using a command called Modemacro. The Modemacro command nds information to the status bar. Diel can be ud with Modemacro to perform simple tasks. Try the following exerci to experiment with Diel:
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 Diel 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 enclod by parenthes. Parenthes are important elements of an expression. All parenthes 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 u to obtain the drawing prefix and name. Try the following to e how DIESEL us 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 u getvar to extract any system variable you want. This can be a great tool when you’re creating custom menus becau 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 ud. Try the following exerci to e how this works:
1. Click the Line tool on the Draw panel.
2. Type ′Modemacro↵. The apostrophe at the beginning of Modemacro lets you u 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 uful in building a menu when you want an option to perform a specific task depending on which command is currently active.
Note: Urs of AutoCAD LT ® software can’t u AutoLISP to find the location of AutoCAD resource files. However, you can u 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.
[]中括号在diel中的⽤途介绍
$(+,val1,val2,…valn)
The sum of the numbers val1, val2,…valn is returned.
OR
返回数字 val1 、 val2 、…、 val9 的和。
$(+, val1 [, val2, …, val9])
如果当前厚度被设定为 5,则以下 DIESEL 字符串返回 15。
$(+, $(getvar, thickness), 10)
晓东论坛还有⼀篇⽂章:
参考⼀下。
Field in Field using Diel
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 Diel 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/Diel Expression.
4. U 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 ems to not work for Diel 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 diel as well, but then it doesn't work at all.