DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Deleting an entity by entity number

Started by Bob P, February 23, 2013, 07:26:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bob P

This should be sooo simple but all I succeed in doing is crashing DC.

This macro must be run in 3d.  I use it to define a mid-plane between 2 lines.  It creates the plane, but then I want to erase the second-to-last entity.  (The line used to make the perp-plane.)  See the commented-out lines at the end.

'This bisects an intersection of two lines with a plane 20X the cursor step
'bis.d3m
SETPOINT "Set a point at the vertex and points on each line: " 3
POINTVAL X Y Z 1
POINTVAL X1 Y1 Z1 2
POINTVAL X2 Y2 Z2 3
SYS(1)=0

'D1=Distance from vertex to first point
D1=((ABS(X1-X))^2+(ABS(Y1-Y))^2+(ABS(Z1-Z))^2)^.5
'D2=Distance from the vertex to the second point
D2=((ABS(X2-X))^2+(ABS(Y2-Y))^2+(ABS(Z2-Z))^2)^.5

'The direction vectors from the origin to the second point are:
DX=(X2-X)/D2
DY=(Y2-Y)/D2
DZ=(Z2-Z)/D2

'The new second point is:
NX=X+DX*D1
NY=Y+DY*D1
NZ=Z+DZ*D1

'Create a line between the new points
>line
{
<POINTXYZ [NX, NY, NZ]
<POINTXYZ [X1, Y1, Z1]
}

'Create a perpendicular plane by setting two points at the midpoint of the line
>PERPENDICULARPLANE
{
'If you want to change the size of the perp plane, change the next line
<width [SYS(30)*20]
<POINTXYZ [(NX+X1)/2, (NY+Y1)/2, (NZ+Z1)/2]
<POINTXYZ [(NX+X1)/2, (NY+Y1)/2, (NZ+Z1)/2]
}

'select next to last entity (the line used to create the perp-plane)
'delete entity
'getattr (sys(9)-1), type, select, laynum, group, red, green, blue
'putattr (sys(9)-1), type, 1, laynum, group, red, green, blue
'>selectdelete
'{
'}

END


prl

#1
Quote from: Bob P on February 23, 2013, 07:26:05 AM
but then I want to erase the second-to-last entity.  (The line used to make the perp-plane.)  See the commented-out lines at the end.


Bob,  I didn't run your program, but here is the general approach.  After you have created the plane (your plane is the last entity) and you want to erase the second to last entity:


.
.
.
.

sys(80) = 0
lastm1 = sys(9) - 1 'last minus one, aka 2nd to last

gettatrr lastm1, type, select
puttattr lastm1, type, 1

if sys(80) > 0 then
  >erase
    {
    }
endif

.
.
.



Edit:  Had to fix my example.  Make sure you are using the code snippet with lastm1 = sys(9) - 1

Bob P

I'm not sure where I was going wrong, but this works! (Slightly modified for a more relevant plane size.)
I use this macro to trim rectangular or round frame rails when their intersection is non-orthogonal.  Could be useful in carpentry also.

Thanks!

'This bisects an intersection of two lines with a plane 20X the cursor step
'bis.d3m
SETPOINT "Set a point at the vertex and points on each line: " 3
POINTVAL X Y Z 1
POINTVAL X1 Y1 Z1 2
POINTVAL X2 Y2 Z2 3
SYS(1)=0

'D1=Distance from vertex to first point
D1=((ABS(X1-X))^2+(ABS(Y1-Y))^2+(ABS(Z1-Z))^2)^.5
'D2=Distance from the vertex to the second point
D2=((ABS(X2-X))^2+(ABS(Y2-Y))^2+(ABS(Z2-Z))^2)^.5

'The direction vectors from the origin to the second point are:
DX=(X2-X)/D2
DY=(Y2-Y)/D2
DZ=(Z2-Z)/D2

'The new second point is:
NX=X+DX*D1
NY=Y+DY*D1
NZ=Z+DZ*D1

'Create a line between the new points
>line
{
<POINTXYZ [NX, NY, NZ]
<POINTXYZ [X1, Y1, Z1]
}

'Create a perpendicular plane by setting two points at the midpoint of the line
>PERPENDICULARPLANE
{
'If you want to change the size of the perp plane, change the next line
planesize=1.6*(((x-x1)^2+(y-y1)^2+(z-z1)^2)^.5)
<width [planesize]
<POINTXYZ [(NX+X1)/2, (NY+Y1)/2, (NZ+Z1)/2]
<POINTXYZ [(NX+X1)/2, (NY+Y1)/2, (NZ+Z1)/2]
}

sys(80) = 0
lastm1 = sys(9) - 1 'last minus one, aka 2nd to last

getattr lastm1, type, select
putattr lastm1, type, 1

if sys(80) > 0 then
  >erase
    {
    }
endif
END