I am going to begin with an example of a diesel macro that is written to insert a block and trim the line...the only difference with this one is that the 0,0 location of the block is offset from the actual center of the block. The reason for this is that when you begin the break command; if you have the insertion point of the block on an actual line entity in that block then it will default that point as its first fence break point.
So, below is an example of a diesel macro that has the insertion point offset from center of the block and how calculate the break points to trim the line.
*^c^cattdia;0;_.insert;GATEV2;\;1;\_USERR3;\_BREAK;$M=$(GETVAR,LASTPOINT);F;@$(*,1,$(+,-.0625,$(GETVAR,USERR1)))<$(GETVAR,USERR3);@$(*,2,$(+,.125,$(getvar,USERR1)))<$(GETVAR,USERR3);Alright, let's go in and break this down some...
The First snippet of code that starts us off is to turn off the attribute dialog box; so, instead of a dialog box this will end up prompting you for the attribute values in the command line which we will just assign a return value to it later on.
Here we have our insert command with the title of the block called out. the "\" calls for user input for the insertion point. "1" is to input the xy scale value of the block, and then the last "\" is to call for user input on the rotation of the block.
In AutoCAD there are 5 "USERR" variables that you can set and it stores that variable so that you can recall it later when you need to. We are just using "USERR3" for this example. So, we call for "USERR3" and then we have "\" to call for user input; and this input is where you will put the rotation angle for you block. So, if you inserted it at a 45° angle then you will enter "45".
Also later on you will see that we call out for "USERR1"...the default for this stored variable is "0"
Here is where we start incorporating Diesel expressions into our macro...
We start with our standard break command, and then we start our Diesel expression. Anytime you want Autocad to evaluate a string as a diesel expression it must begin with "$M="...this is what tells Autocad that you are beginning a diesel string. So, in this example we are telling Autocad to find the insertion point of the block since that was the last point that was used. Once done with that then you want to move into the fence command by using "F".
Okay, here is where you need to know the distance from the insertion point of your block to the far left edge of your block.
First we start the point evaluation with "@"; this is the old style of point definition with polar coordinates.
Then we tell it that we are going to start another Diesel expression. So, within that first grouping of parenthesis we find "$(+,-.0625,$(Getvar,userr1)); here we are saying...starting at the insertion point I want to move -.0625, but you have to have to do this with a formula. And when doing a formula with diesel this is how it is to be set up:
Then we also have "$(*,1" here we are just telling it to multiply that previous formula by 1.
and then we pass it the system variable that we set up for the rotation of the block at insertion.
The second point is basically set up the same way as the previous evaluation string; the only difference is I have within the first formula I am moving it half the distance of the block with "$(+,.125,$(getvar,USERR1))" and then I am telling it to multiply that formula by a value of 2.
Diesel programming is very useful when you have an office that have half the people on full Autocad and then the other half on Autocad LT.