DIESEL编程举例

DIESEL Programming Examples

Z=0

VG-Wort Access-ZählmarkeAsks for a point, then moves this point to the X/Y plane by setting Z to zero.

[Z=0]^C^C_setvar;osmode;0;_id;\+
_stretch;_c;+
$M=$(-,$(index,0,$(getvar,lastpoint)),$(/,$(getvar,viewsize),10)),+
$M=$(-,$(index,1,$(getvar,lastpoint)),$(/,$(getvar,viewsize),10));+
$M=$(+,$(index,0,$(getvar,lastpoint)),$(/,$(getvar,viewsize),10)),+
$M=$(+,$(index,1,$(getvar,lastpoint)),$(/,$(getvar,viewsize),10));;+
_end;@;.xy;_end;@;0;

Curved leader

Draws a curved leader. Uses a predefined block ARROW. There are two macros for left and right leaders.

[/CCurved leader right]^c^c_insert;arrow;\+
$M=$(*,$(getvar,dimscale),$(getvar,dimasz));;\+
_pline;@;\\\@$M=$(*,$(getvar,dimscale),$(getvar,dimasz))<0;;+
_pedit;_l;_spline;;+
_text @$M=$(*,$(getvar,dimscale),$(getvar,dimgap))<0;+
$M=$(*,$(getvar,dimscale),$(getvar,dimtxt));0;\
[/uCurved leader left]^c^c_insert;arrow;\+
$M=$(*,$(getvar,dimscale),$(getvar,dimasz));;\+
_pline;@;\\\@$M=$(*,$(getvar,dimscale),$(getvar,dimasz))<180;;+
_pedit;_l;_spline;;+
_text _r @$M=$(*,$(getvar,dimscale),$(getvar,dimgap))<180;+
$M=$(*,$(getvar,dimscale),$(getvar,dimtxt));0;\

Break Dline

Breaks a double line. Shows how to use a local coordinate system.

[Break DLine]+
^c^cmodemacro;Select first line:;+
_ucs;_entity;\+
modemacro;Select first break point:;+
_ucs;_origin;.yz;0,0,0;\+
modemacro;Select second break point:;+
_break;0,0;\+
modemacro;Select second line:;+
_break;_per;\.y;@;0;+
modemacro;.;+
_ucs;_prev;+
_ucs;_prev

Break Dline2

Same, but uses local variables and trims.

[Break Dline2]+
^c^c_modemacro;Select first break point on first line;+
_id;_nea;\_setenv;dlbreaka;$m=$(getvar,LASTPOINT);+
_text;@;;;"$M=$(getenv,dlbreaka)";+
_modemacro;Select second break point on second line;+
_id;_nea;\_setenv;dlbreakb;$m=$(getvar,LASTPOINT);+
_text;@;;;"$M=$(getenv,dlbreakb)";+
_line;"$M=$(getenv,dlbreaka)";_per;"$M=$(getenv,dlbreakb)";+
_select;_last;;+
_setenv;dlbreakc;$M=$(getvar,LASTPOINT);+
_copy;_last;"$M=$(getenv,dlbreakc)";"$M=$(getenv,dlbreakb)";+
_select;_prev;_last;;+
_trim;_prev;;_fence

Arc length

Displays the length of an arc. Demonstrates how to prompt for input.

[Arc length]+
^c^c_undo;_group;+
_modemacro;Select arc:;+
_pedit;\_y;;+
_modemacro;.;+
_area;_e;@;+
_undo;_end;+
_perimeter;+
_u;

Last edited

Places the date of the drawing's last modiffication on the drawing. There are two macros for US date format and international format.

[Last edited US]^c^c_text;$M=$(getvar,viewctr);;0;+
Last edited: $m=$(edtime,$(getvar,tdupdate),MO/DD/YY H:MM);+
modemacro;Enter date placement;+
_move;_l;;@;\+
modemacro;.;
[Last edited intl.]^c^c_text;$M=$(getvar,viewctr);;0;+
Last edited: $m=$(edtime,$(getvar,tdupdate),D.M.YY H:MM);+
modemacro;Enter date placement;+
_move;_l;;@;\+
modemacro;.;

A note on the TEXT command: Different versions of AutoCAD make different use of the TEXT command used to insert single-line text into a drawing. The macro shown will work without modification in AutoCAD up to Release 14 and LT up to LT 98. In AutoCAD (LT) 2000i you need to use the command -TEXT (with a leading dash) instead. In AutoCAD (LT) 2000 neither one works. There my advice is to update to the i versions. If you don't want to, you need to use an attributed block or the command line version of the paragraph text command (-MTEXT) to place text in a drawing.

Rotated Copy

Places a rotated copy of selected entities.

[ROTATED COPY]+
$M=$(if,$(eq,$(substr,$(getvar,cmdnames),1,4),GRIP),_rotate;_copy,+
^C^C_select;_auto;\_copy;_p;;"0,0";;_rotate;_p;;)

Align objects

This emulates the ALIGN command found in full AutoCAD. Select the objects to align, then in sequence: a point on the objects to align, the target point where this point is going to land, a second point on the objects to align, the target point where this point is going to land. If the distances differ, the second target point only defines the direction, not any scaling.

[Align]+
^C^C_select;\_move;_p;;\\_rotate;_p;;@;_ref;@;\\

Half a line

Asks for two points, then draws a line from first point half the distance to the second point. Demonstates delaying of DIESEL evaluation.

[Half a line]+
^C^C_id;\_setenv;P1;$M=$(getvar,lastpoint);+
_id;\_setenv;P2;"$M=$(getvar,lastpoint)";+
_line;"""$M=$(getenv,P1);$(getenv,P2);;+
_lengthen;_p;50;$(getenv,P2);"""

Autonumber

Draws a number with every pick and automatically increments it. Uses style, height and rotation of last drawn text. Setvar start value as USERI1.

[Autonumber]*^c^ctext;_m;\;;$M=$(getvar,USERI1);setvar;USERI1;$(+,1,$(getvar,USERI1))

Please read the note on the TEXT command as well.

Insert Area value

Inserts the area of any previously measured object/area as text into the drawing. This macro needs a block named AREABLK located in the current drawing, the template drawing or anywhere on AutoCAD's search path. AREABLK has to have exactly one attribute which will be filled with the area value.

^C^Cattdia;0;_-insert;AREABLK;\1;1;0;$M=$(getvar,AREA);attdia;1

In-the-middle-of Snap

Demonstrates how to write a macro that runs transparently within any other command. This one calculates the midpoint between two points selected, e.g. the center of a rectangle. Uses LIMMIN and LIMMAX which are 2D points.

'_setenv;P1;$M=$(getvar,limmin);'_setenv;P2;$(getvar,limmax);'_limmin;\'limmax;+
\"$M=$(/,$(+,$(index,0,$(getvar,limmin)),$(index,0,$(getvar,limmax))),2.0),+
$(/,$(+,$(index,1,$(getvar,limmin)),$(index,1,$(getvar,limmax))),2.0);+
'limmin;$(getenv,P1);'limmax;$(getenv,P2);"

Dimension an arc's length

This macro was written by Erik Verbeeck. It dimensions an arc using the arc's length instead of the included angle.

^C^C$m=ortho;off;_arc;\$m=_c;cen;@;\pe;l;;;area;o;l;$m=e;l;;dimangular;;cen;+
"$(getvar,lastpoint);$(getvar,lastpoint);""$(getvar,lastpoint);t;$(rtos,$(getvar,perimeter))""";+
\chprop;l;;la;dimension;;orthomode;$(getvar,orthomode);

Text on Arc

Below is a very complex DIESEL macro, written by Robert Freeman. It demonstrates several useful programming techniques, most importantly it demonstrates how to create loops in DIESEL. You will need some time to study how this macro works (as did I), but it's worth the effort. Some hints: Watch for ct1 and ct2. ct1 is a flag which lets the macro run through a couple of alternatives, ct2 is a counter which loops from 1 to the end of the string to write. Many thanks to Robert Freeman for posting this code in the AutoCAD LT newsgroup. We tried to get an explicit permission from him to re-post it here, but unfortunately the email address listed in the comments does not work any more. Robert, if you're listening, please contact me at dietmar@crlf.de.

Please read the note on the TEXT command as well.

***MENUGROUP=ArcText
***Pop1
[Text on Arc]
//
//Description
//
//This is a partial menu file that contains a macro to wrap text around an arc.  It
//prompts for two points and a text string, and then pops up a cursor menu asking
//how you want the text orientated.
//
//This macro was developed in and for AutoCAD LT 97.  It may also work in earlier
//versions but has not been tested in them.
//
//Author
//
//Robert Freeman
//rfreeman@rconnect.com
//
//Installation
//
//Please consult your AutoCAD LT 97 documentation for instructions on installing
//partial menu files.  Only insert the menu entitled "Text on Arc".  Do not insert
//the menu entitled "Cursor".
//
//**IMPORTANT**IMPORTANT**IMPORTANT**
//
//Before you begin
//
//        1.  Before you can begin using the "Text on Arc" macro you must first select
//            "Reset" from the "Text on Arc" menu item.  This creates and sets a number of
//            environmental variables needed by the "Text on Arc" macro.  You only have to do
//            this the first time you use the macro.
//
//        2.  This macro assumes that the current text style is set to a fixed text height and that
//            text height is equal to the "TEXTSIZE" system variable.  If the current
//          text style text height is set to 0, this macro will fail.  The "Reset" macro
//            will prompt for this value and will change both the current setting of the "TEXTSIZE"
//            system variable and the text height of the current text style. Search AutoCAD LT help for
//          the STYLE command if you don't understand this.  Also, the text size is assumed to be
//            at full scale.
//
//        3.  This macro makes use of the PSPROLOG system variable for text entry.  This
//            variable is used by AutoCAD LT to assign a name for a prolog section to be read
//            from the aclt.psf file when using the PSOUT command.  Its default value is "".
//
//            If you do not export encapsulated PostScript (ESP) files, this should not cause you
//            any problems.  If you do use ESP files and PSPROLOG normally is set to some value,
//            you should check to be sure that its value is set correctly before you use the PSOUT
//            command.  You can do this by selecting the Options button in the PSOUT dialog box.
//            The macro does attempt to store and reset this value, however if the macro is cancelled
//            prematurely, this value may be lost.
//
//Using the "Text on Arc" macro.
//
//        1.  Select "Text on Arc" from the ArcText menu.
//
//        2.  You will be prompted for the center point of the arc you want your text to wrap around.
//
//        3.  Next select the middle point of your text.
//
//        4.  You will then be prompted to enter a text string.  Enter your text string and press enter.
//
//        5.  A cursor menu will then pop up with two items - "Bottom of text points toward the radius" and
//            "Bottom of text points away from the radius.  Select one.  Note: If the length of your text
//            string exceeds the circumference of a circle drawn around the radius point you selected, you
//            will receive the error message "Text string too long."  Try again using a shorter text string
//            or select a middle point farther away from your center point.
//
//        6.  Although the macro is entitled "Text on Arc", you do not have to select the center of
//            an actual arc.  Any point will do.  The arc the text wraps around is calculated using the
//            distance between the two points you select as the radius.
//
//        7.  An UNDO with the BACK option will delete your text if you make an error.
//
//Known issues
//
//        1.  If you cancel the macro before it completes, the macro probably won't work correctly the
//            next time you use it.  Select "Reset" from the menu to correct for this situation.
//
//        2.  Even though the system variable MENUECHO is set to 3 (suppress everything possible), you
//            may see extra text after the various prompts.  In particular, you may see the text "ID"
//            when the macro prompts for the center point.  Although it makes the prompts look bad, it
//            does not cause any problems.  Unfortunately, this does not happen every time. This has
//            made it difficult to find a solution.
//
//        3.  If you enter a text string with a single quotation mark followed by a space, all characters
//            from the quotation mark to the end of the string will be truncated.  For example if you enter
//            the string Delta=90d00'00" Radius=10,  it will be truncated to Delta=90d00'00.  The work
//            around is to replace the space after the single quotation mark with a dummy character and then
//            erase it afterwards.
//
//        4.  If you decide to add your own enhancements to this macro, be aware that there is an apparent
//            bug in ACAD LT 97's menu interpreter that causes ACAD LT 97 to crash if the number of characters
//            under a label exceeds about 2200 characters.  Tech support confirmed to me that this is a problem
//            [they duplicated the situation on their PC's] but unfortunately they said they have no plans
//            to issue a patch for this problem.
//
//Environmental variables used
//
//cd  = character delta - central angle in radians of a single character's arc length
//cps = current psprolog setting - saves users current psprolog setting
//csm = current snap mode - saves users current Osmode setting
//ct1 = counter number 1
//ct2 = counter number 2
//ern = error number - Used to determine if an error occurs
//er2 = error message 2 - "Text string is too long."
//er3 = error message 3 - "Radius cannot equal 0."
//mb  = midpoint bearing - Direction from pt1 to pt2
//ob  = offset bearing - Direction from radius to middle point of each character
//pm3 = prompt 3 - "Enter center point of arc:"
//pm7 = prompt 7 - "Enter middle point of text:"
//pm6 = prompt 6 - "Enter text: "
//pm8 = prompt 8 - "Enter text size. Value MUST equal current style text height setting:"
//pmb = prompt b = Concatenation of variable pm8 and current setting of the system variable "textsize".
//pt1 = point number 1 - Center point of arc
//pt2 = point number 2 - Middle point of text
//qt  = quotation mark - "
//rd  = radius = Distance from pt1 to pt2
//sb  = start bearing - Direction from radius to middle point of first character
//st  = string value - Text string to be arced
//sl  = string length - Number of characters in st
//tb  = text bearing - Rotation angle of each character of text
//td  = text delta - Central angle in radians of st arc length
//tl  = text length - Arc length of st
//
//System variables used
//
//osmode - Set to 0.  Users current settings are saved and reset
//menuecho - Set to 3 to suppress everything possible.  Reset to 0 at end of macro.
//lastpoint - Used to set pt1 and pt2
//distance - Used to set rd
//chamferd - Used to set mb
//psprolog - Used to retrieve text string.  Used because it is one of the few
//             system variables that will accept embedded spaces and punctuation.
//             Users settings are saved and reset.
//
[Reset]^C^C+
MENUECHO;3;+
SETENV;cd;0;+
SETENV;ct1;0;+
SETENV;ct2;1;+
SETENV;ern;0;+
SETENV;er2;"Text string is too long.";+
SETENV;er3;"Radius cannot equal 0.";+
SETENV;mb;0;+
SETENV;ob;0;+
SETENV;qt;";+
SETENV;pm3;"Enter center point of arc:";+
SETENV;pm7;"Enter middle point of text:";+
SETENV;pm6;"Enter text:";+
SETENV;pm8;"Enter text size. This will change current style text height setting.";+
SETENV;pmb;$M=$(getenv,qt)$(getenv,pm8)<$(getvar,textsize)>:$(getenv,qt);+
SETENV;pt1;0;+
SETENV;pt2;0;+
SETENV;rd;0;+
SETENV;sb;0;+
SETENV;sl;0;+
SETENV;st;"";+
SETENV;td;0;+
SETENV;td;0;+
SETENV;tl;0;+
GETENV;pmb;+
TEXTSIZE;\+
-STYLE;;;"$M=$(getvar,textsize)";;;;;;+
MENUECHO;0;+

[Text on Arc]*^C^C+
$M=$(if,$(=,$(getenv,ct1),0),+
UNDO;M;+
MENUECHO;3;+
SETENV;csm;$(getvar,osmode);+
OSMODE;0;+
SETENV;ern;0;+
GETENV;pm3;+
ID;\)+
$(if,$(=,$(getenv,ct1),0),+
SETENV;cps;$(getenv,qt)$(getvar,psprolog)$(getenv,qt);)+
$(if,$(=,$(getenv,ct1),1),+
SETENV;pt1;$(getvar,lastpoint);+
GETENV;pm7;+
ID;\+
GETENV;pm6;+
PSPROLOG;\)+
$(if,$(=,$(getenv,ct1),2),+
SETENV;pt2;$(getvar,lastpoint);+
SETENV;st;$(getenv,qt)$(getvar,psprolog)$(getenv,qt);+
PSPROLOG;$(getenv,cps);)+
$(if,$(=,$(getenv,ct1),3),+
SETENV;sl;$(strlen,$(getenv,st));+
DIST;$(getenv,pt1);$(getenv,pt2);+
CHAMFERD;$(getenv,pt1);$(getenv,pt2);)+
$(if,$(=,$(getenv,ct1),4),+
SETENV;rd;$(getvar,distance);+
SETENV;mb;$(getvar,chamferd);+
SETENV;tl;$(*,$(getenv,sl),$(getvar,textsize));+
$(if,$(=,$(getvar,distance),0),+
SETENV;ern;3;))+
$(if,$(=,$(getenv,ct1),5),+
SETENV;td;$(/,$(getenv,tl),$(getenv,rd));)+
$(if,$(=,$(getenv,ct1),6),+
SETENV;cd;$(/,$(getenv,td),$(getenv,sl));+
$(if,$(>,$(getenv,td),6.2832),+
SETENV;ern;2;)+
SETENV;ct1;0;+
SETENV;ct2;1;+
$P0=ArcText.Cursor $P0=*)+
$(if,$(<,$(getenv,ct1),6),+
SETENV;ct1;$(+,$(getenv,ct1),1))+
$(if,$(!=,$(getenv,ern),0),+
;SETENV;ct1;0;+
MENUECHO;0;+
SETENV;ern;0;+
^C^C+
GETENV;er$(getenv,ern))

**Cursor

[Cursor]

[Bottom of text points toward Radius]*^C^C+
$M=$(if,$(=,$(getenv,ct1),0),+
SETENV;sb;$(-,$(+,$(/,$(getenv,td),2),$(getenv,mb)),$(*,$(getenv,cd),0.5));+
UCS;O;$(getenv,pt1);+
SETENV;ct1;$(+,$(getenv,ct1),1))+
$(if,$(=,$(getenv,ct1),1),+
SETENV;ob;$(-,$(getenv,sb),$(*,$(getenv,cd),$(-,$(getenv,ct2),1)));+
SETENV;tb;$(-,$(-,$(getenv,sb),$(*,$(getenv,cd),$(-,$(getenv,ct2),1))),1.57079633);+
SETENV;ct1;2;)+
$(if,$(=,$(getenv,ct1),2),+
TEXT;J;C;$(-,$(getenv,rd),$(*,$(getvar,textsize),0.5))<$(getenv,ob)r;$(getenv,tb)r;$(substr,$(getenv,st),$(getenv,ct2),1);+
SETENV;ct2;$(+,$(getenv,ct2),1);+
SETENV;ct1;1;)+
$(if,$(=,$(getenv,ct2),$(+,$(getenv,sl),1)),+
UCS;W;+
SETENV;ct2;1;+
SETENV;ct1;0;+
OSMODE;$(getenv,csm);+
MENUECHO;0;+
^C^C$)

[Bottom of text points away from radius]*^C^C+
$M=$(if,$(=,$(getenv,ct1),0),+
SETENV;sb;$(-,$(-,$(getenv,mb),$(/,$(getenv,td),2)),$(*,$(getenv,cd),0.5));+
UCS;O;$(getenv,pt1);+
SETENV;ct1;$(+,$(getenv,ct1),1))+
$(if,$(=,$(getenv,ct1),1),+
SETENV;ob;$(+,$(getenv,sb),$(*,$(getenv,cd),$(getenv,ct2)));+
SETENV;tb;$(-,$(+,$(getenv,sb),$(*,$(getenv,cd),$(getenv,ct2))),4.71238898);+
SETENV;ct1;2)+
$(if,$(=,$(getenv,ct1),2),+
TEXT;J;C;$(+,$(getenv,rd),$(*,$(getvar,textsize),0.5))<$(getenv,ob)r;$(getenv,tb)r;$(substr,$(getenv,st),$(getenv,ct2),1);+
SETENV;ct2;$(+,$(getenv,ct2),1);+
SETENV;ct1;1)+
$(if,$(=,$(getenv,ct2),$(+,$(getenv,sl),1)),+
;UCS;W;+
SETENV;ct2;1;+
SETENV;ct1;0;+
OSMODE;$(getenv,csm);+
MENUECHO;0;+
^C^C$)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值