News:

Please note new Forum URL: forum.designcad.com

Main Menu
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.

Correct macro code for entity J

Started by aqua, April 14, 2010, 10:21:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aqua

Designcad 13.13

I have a number of macros and note some different code in these.

Can experienced macro code writers confirm if code 1 is suitable or incorrect?

Also, with code 3, is the extra
getselect j, a
Entity a
required, or could this have been merged or similar to code 2?


Concerned with the entity j etc part of the code: example

Entity j
    getattr j, type, select, laynum, group, red, green, blue


Regards Frank


Macro Code 1
'This code not working, appears to be using j from earlier macro code, appears to be selecting laynum of items in order drawn, was using fence 105, deleted this, now using 234
for j = 1 to sys(80)

    Entity j
    getattr j, type, select, laynum, group, red, green, blue

if LENGTH(j) > 100 and laynum = 240 and type = 1 then
pointval xc yc zc 1 'first point of selected entity
'......extra code as required
endif
next


Macro Code 2
'This code appears okay
for j = 1 to sys(80)


GetSelect j, k 'store the entity id of selected entity j in k
Entity k
    getattr k, type, select, laynum, group, red, green, blue


    if LENGTH(j) > 100 and laynum = 240 and type = 1 then
pointval xc yc zc 1 'first point of selected entity
'.....extra code as required
endif
next




Macro Code 3
for j = 1 to sys(80)
GetSelect j, k 'store the entity id of selected entity j in k
Entity k
    getattr k, type, select, laynum, group, red, green, blue
    if LENGTH(j) > 100 and laynum = 240 and type = 1 then
getselect j, a
Entity a

pointval x2c y2c z2c 1 'first point of selected entity
pointval x3c y3c z3c 2 'first point of selected entity
'....extra code as required
end if
next

paulerens

#1
Frank,
This works for me.
>SelectAll
{
}
a = Sys(80)
Points = Sys(80)
Dim x(Points)
Dim Y(Points)
Dim z(points)
For i = 1 To Sys(80)
getselect i,j
 Entity j
   getattr i, type, select, laynum, group, red, green, blue
if LENGTH(i) > 100 and laynum = 240 and type = 1 then
    Pointval x(i),y(i),z(i),1 'Recorded only the first point of the lines which meet the criterion.
End If
Next i
>Deselect
{
}
For L = 1 to a
>PointSelect                    ' Selects only the desired lines to see if it is OK.
{
<Type 1
<Pointxyz [x(L),y(L),z(L), 1]
}
Next L
End

Paul

DrollTroll

Frank,

Macro code one has the following effect:
If you have 10 items selected (i.e. sys(80) = 10), then

For j = 1 to Sys(80)
Entity j

just selects the first ten objects in the drawing, not the first ten SELECTED objects. That's what GetSelect is for, is to get the entity ID of the nth SELECTED object. So...

For j = 1 to Sys(80)
GetSelect j, k
Entity k

selects only the ten SELECTED objects. (i.e. for the jth selected object, GetSelect returns its Entity ID as k)


For Macro code 3, the GetSelect j, a and Entity a appear unnecessary -- the entity was already "picked" with the previous GetSelect and Entity statements.
25 years with DesignCAD

aqua

Designcad 13.13

Thanks guys.

Code 1 and Code 2 was in a macro that was waiting for completion.
It was cut from other macros that were sourced from the forum.

Code 1 might be an issue in some of my other macros, if I want to look at selected items rather than all items.

Code 2 is what I have used.

Code 3 is in another macro, and would have been taken as supplied by the forum.
However in comparing it to code 2, I figured it could have been cleaner which Droll Troll has confirmed.

In the early days, I would take code as supplied, if it worked, I would leave it alone.

bdeck

#4
The following is correct for some operations, but defective for others, notably solids.

For j = 1 to Sys(80)
   GetSelect j, i
   Entity i
   gosub process
next j


Dempsey pointed that out in a prior discussion :http://forum.designcad.com/index.php?topic=1535.0

Also third parameter returned by getattr must be decoded: http://forum.designcad.com/index.php?topic=1549.msg8025#msg8025


To make certain all selected entities are processed, use the following.


for i =1 to sys(9)
  getattr i, t, s
  if s mod 2 then gosub process
next i

or use

for i =1 to sys(9)
  getattr i, t, s
  if (s=1) or (s=3) then gosub process
next i

or use

Alias ENT_SELECTED  &H010C  
for i =1 to sys(9)
  entity i
  query ENT_SELECTED, s
  if s then gosub process
next i


BD

Lar

Quote from: bdeck on April 25, 2010, 11:03:49 AM
The following is correct for some operations, but defective for others, notably solids.

For j = 1 to Sys(80)
   GetSelect j, i
   Entity i
   gosub process
next j

...
...

To make certain all selected entities are processed, use the following.


for i =1 to sys(9)
  getattr i, t, s
  if s mod 2 then gosub process
next i

or use

for i =1 to sys(9)
  getattr i, t, s
  if (s=1) or (s=3) then gosub process
next i

or use

Alias ENT_SELECTED  &H010C  
for i =1 to sys(9)
  entity i
  query ENT_SELECTED, s
  if s then gosub process
next i


BD

DB, in all your sample macros you mention "gosub process" (highlighted in red above) but there is no "process" to sub to (I looked for it among the other macros in this thread but don't see it. If it's there please forgive me). I'm just concerned that non-macro-writers reading this thread may try to run them and you know what will happen (will get an error, for you non-macro-writer readers).

Lar


bdeck

#6
Hi Lar,

Right you are, and  here it is.

Process:  ' Should have been myProcess, or some other clearly user defined procedure name
   'do here whatever you would have done there
return

You have reminded me of all the worst examples in programming books that I swore never to emulate, but now do. The worst offenders were the ones where labels for variable names, class names, and user procedures  resembled language key words, forcing one to slowly parse every line for meaning.

Mea Culpa

BD