Author Topic: A Point Walker  (Read 2650 times)

bdeck

  • Hero Member
  • *****
  • Posts: 780
A Point Walker
« on: December 26, 2006, 07:19:05 PM »
Ive had this utility so long, i cant remember writing it.
I find it useful for analyzing entities and writing macros.
Maybe it will save someone a few minutes on the next project.

Regards,
BD


Edit 11/15/08:

This is an older version.

Find an updated version in the following message in this queue.  



'APW.d3m      12/06   brent deck

'POINTWALKER    
'WALKS THROUGH EACH POINT OF AN ENTITY, BY NUMBER
'
'Instructions:
'     Select an entity,
'     Run the macro,
'     Read point numbers in status bar.



red0=sys(300)           ' archive colors
green0=sys(301)
blue0=sys(302)

ne=sys(80)   ' look for selected entities
d=0
if ne =0 then end   ' if no entities are selected then end  

getselect 1,entno
>deselect
{
}
GETATTR entno, type ,select, laynum, group, red, green, blue, solid

sys(1)=0
entity entno
np=sys(1)
dim x(np), y(np), z(np)
for i=1 to np
   pointval x(i) y(i) z(i) i
next i
sys(1)=0

for i=1 to np
    >PointMark
    {
      <Type 1
      <Color 255, 100, 100
      <Size 1
      <Pointxyz [x(i), y(i), z(i)]
    }

    print i," of  ",np,"   ent",entno," type ",type
    message "next point"
    >EraseLast
    {
    }
next i

cleanup:

     sys(1)=0
     sys(300)=red0
      sys(301)=green0
      sys(302)=blue0

end

« Last Edit: April 22, 2012, 09:10:19 PM by bdeck »

bdeck

  • Hero Member
  • *****
  • Posts: 780
Re: A Point Walker
« Reply #1 on: November 15, 2008, 12:38:38 PM »
Here's an updated version for examining points in multiple selections, groups, or grids.

Edit 1/31/2015 Note: The SetColor command in this version causes a fatal error in later DC versions (18-25). Fixed in an updated version later in this thread

BD

Edit 2/28/09 to add clean escape key bailout
Edit 2/2/11 to scale point size to screen width and make shape more visible
Code: [Select]

'APW.d3m    versoin 2   11/08 bd
'
'A POINT WALKER
'WALKS THROUGH EACH POINT OF EACH SELECTED ENTITY, BY NUMBER
'
'Select one or more entities.
'Run macro.
'Follow instructions on status bar.
'
'
' This version modified to highlight individual entities while enumerating their points.
'

' ****************   Setup  *****************
'Choose display point color, size and type
red=0
green=200
blue=0
ps=(sys(601)-sys(600))/40      ' scale point size to screen width   
pt=2
' ***************** end setup **************


Alias ENT_NPTS  &H010D
Alias ENT_POINT  &H010E 

if sys(80) =0 then
message "no items selected"
end   ' if no entities are selected then end 
endif

sys(1)=0
dim x(10000), y(10000), z(10000)

red0=sys(300)
green0=sys(301)
blue0=sys(302)



gosub archive

for entno = 1 to sys(9)
if entsel(entno) then
>deselect
{
}
GETATTR entno, type, sel, laynum, grp 
putattr entno, type, 1

'Now redraw highlighted selection
>SetHandle
    {
<Pointxyz 0,0,0
<Pointxyz 0,0,0
<Pointxyz 0,0,0
<Type 0
    }           
gosub regenlite  'will not work without first setting handles

entity entno
if type=34 then
     grptrgt=sys(91)
else
     grptrgt=-1
endif
query ent_npts, np
if np > 0 then
                for i=1 to np
query ent_point, i x(i) y(i) z(i)
next i

for i=1 to np

>PointMark    ' place a temporary point mark on sceen to show point location
{
<Color [red, green, blue]
<Type [pt]
<Size [ps]
<Pointxyz [x(i), y(i), z(i)]
}
>SetColor  ' reset color
{
<Color [red0, green0, blue0]
}

print "point ", i," of  ",np,"   ent=",entno," type=",type," grp=",grp,"grptrgt=", grptrgt," press a key for next point"
anykey kcode
>EraseLast
{
}
if kcode=27 then 'bailout
i= np
entno = sys(9)
endif
next i
endif
if entsel(entno) and kcode<>27 then
a$=np
e$=entno
                m$ = "Queried no of pts for entity "+e$+"  =  " +a$+"   "
message m$
endif
endif
next entno

cleanup:
sys(1)=0
>deselect
  {
  }
gosub restore
gosub regenlite
end




archive:      '  archive current selection set
 if sys(80)>0 then
    ns=0
    ne=sys(9)
    dim entsel(ne+1)
    for i=1 to ne
       getattr i,t,sel
       entsel(i) = sel mod 2  ' nearest thing to a bitwise (AND 1) available in DC
       ns=ns+entsel(i)
    next i

    sys190=sys(190)    ' archive handles
    sys191=sys(191)
    sys192=sys(192)
    sys193=sys(193)
    sys194=sys(194)
    sys195=sys(195)
    sys202=sys(202)
    sys203=sys(203)
    sys204=sys(204) 
  endif
return

restore:    ' restore original selection set and handles
    if ns>0 then
       For i = 1 To ne   'Reselect all prior selected items
          if entsel(i) then
               Getattr i, type, sel
               if  sel <> 1 then  Putattr i, type, 1    ' eliminate prior selection flag for all selected ents 
           endif
        Next i
    endif
   
    >SetHandle
    {
<Pointxyz [sys190, sys191, sys202]
<Pointxyz [sys192, sys193, sys203]
<Pointxyz [sys194, sys195, sys204]
<Type 0
    }

return

regenlite:           ' fast redraw of selected areas only
>move   
{
<type 1
<Reference 1
<Pointxyz 0,0,0
<Pointxyz 0,0,0
}
return



« Last Edit: January 31, 2016, 03:40:14 PM by bdeck »

Lar

  • Hero Member
  • *****
  • Posts: 2477
Re: A Point Walker
« Reply #2 on: February 12, 2011, 06:50:18 AM »
Very useful macro bdeck. Wish I found it earlier.

Lar

Wow! It's been here since 2006. Wish I had a dime for every time in the last 4 years I could have used it.
I use to use the 'Points' section in the info box and set one of the values of the point I needed to zero (so it moved) then undo to locate a particular point. This macro with all the extra info it provides is so much better.
« Last Edit: February 12, 2011, 06:56:24 AM by Lar »

bdeck

  • Hero Member
  • *****
  • Posts: 780
Re: A Point Walker
« Reply #3 on: February 12, 2011, 08:09:38 PM »
Thanks Lar,

I hadnt looked at this in a while.

I edited it today to scale the point size relative to the screen width. Also changed to a more visible point shape.

Its still a bit rough, but in another 4 years it might be better.

It reads the entity count of group entities as a point count (as does the query command). It then highlights whatever points it has in its buffer to represent the entity count of the group, even though those points may not belong in that group. I just ignore it, but thats an area that could use some dressing up. Grid entities need similar attention.


Best Regards,

BD
« Last Edit: February 13, 2011, 08:49:10 AM by bdeck »

bdeck

  • Hero Member
  • *****
  • Posts: 780
Re: A Point Walker
« Reply #4 on: January 31, 2016, 03:06:09 PM »
Here's an update that fixes some major and minor issues.

The SetColor command appears to cause a fatal error in recent DC versions on my PC.  Changed to a sys() variable setting, and moved to the "restore:" subroutine.

Groups handled more cleanly now, with an option to ignore them altogether.

bd
Code: [Select]
'APW.d3m    version 3  01/31/16  bdeck 
'
'A POINT WALKER
'WALKS THROUGH EACH POINT OF EACH SELECTED ENTITY, BY NUMBER
'
'Select one or more entities.
'Run macro.
'Follow instructions on status bar.
'
' This version modified to eliminate "SetColor" command.
' Also now queries points indiviually as needed, rather than dimensioning an array of points.

' Highlights individual entities while enumerating their points.
'

' ****************   Setup  *****************

'Choose display point color, size and type
red=0
green=200
blue=0
ps=(sys(601)-sys(600))/40      ' scale point size to screen width   
pt=2
showgroups=1                   ' 1 to show group info, 0 to ignore

' ***************** end setup **************

Alias ENT_NPTS  &H010D
Alias ENT_POINT  &H010E
Alias ENT_SELECTED  &H010C 

if sys(80) =0 then
message "no items selected"
end   ' if no entities are selected then end 
endif

sys(1)=0

gosub archive

for entno = 1 to ne
 
  if entsel(entno) then
>deselect
{
}
GETATTR entno, type, sel, laynum, grp
putattr entno, type, 1

'Now redraw highlighted selection

>SetHandle
   {
<Pointxyz 0,0,0
<Pointxyz 0,0,0
<Pointxyz 0,0,0
<Type 0
   }

gosub regenlite  'will not work without first setting handles

entity entno
query ent_npts, np

if (type =34) then
   if showgroups then
    grpID=sys(91)
    if entsel(entno) then
a$=np
e$=entno
g$=grpID
                m$ = "Entity number "+e$+" is a Type 34 Container for Group "+g$+" of " +a$+" entities "
message m$
    endif
   endif

else
      if (np > 0) then
               for i=1 to np
query ent_point, i x, y, z
next i

for i=1 to np

entity entno
query ent_point, i x, y, z

>PointMark    ' place a temporary point mark on sceen to show point location
{
<Color [red, green, blue]
<Type [pt]
<Size [ps]
<Pointxyz [x, y, z]
}

print "point ", i," of  ",np,"   ent=",entno," type=",type,"grp=",grp," press a key for next point"

anykey kcode
if sys(9)>ne then
>EraseLast
{
}
endif
if kcode=27 then 'bailout
i= np
entno = ne
endif
next i

    endif

     if entsel(entno) and kcode<>27 and type <> 34 then
a$=np
e$=entno
                m$ = "Queried no of pts for entity "+e$+"  =  " +a$+"   "
message m$
   endif
   endif
endif
next entno


cleanup:
sys(1)=0
>deselect
  {
  }
gosub restore
gosub regenlite
end


archive:      '  archive current selection set, color, and handles

red0=sys(300)
green0=sys(301)
blue0=sys(302)


 if sys(80)>0 then
    ns=0
    ne=sys(9)
    dim entsel(ne+1)
    for i=1 to ne
       getattr i,t,sel
       entsel(i) = sel mod 2  ' nearest thing to a bitwise (AND 1) available in DC
       ns=ns+entsel(i)
    next i

    sys190=sys(190)    ' archive handles
    sys191=sys(191)
    sys192=sys(192)
    sys193=sys(193)
    sys194=sys(194)
    sys195=sys(195)
    sys202=sys(202)
    sys203=sys(203)
    sys204=sys(204) 
  endif
return

restore:    ' restore original color, selection set and handles

sys(300)=red0
sys(301)=green0
sys(302)=blue0

do while ne<sys(9)  'now erase any stray pointmarks
>EraseLast
{
}
loop

    if ns>0 then
       For i = 1 To ne   'Reselect all prior selected items
          if entsel(i) then
       entity i
       Change Ent_Selected, 1
       update
          endif
        Next i
    endif
   
    >SetHandle
    {
<Pointxyz [sys190, sys191, sys202]
<Pointxyz [sys192, sys193, sys203]
<Pointxyz [sys194, sys195, sys204]
<Type 0
    }

return

regenlite:           ' fast redraw of selected areas only



>move   
{
<type 1
<Reference 1
<Pointxyz 0,0,0
<Pointxyz 0,0,0
}
return

« Last Edit: February 12, 2016, 11:23:35 AM by bdeck »