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.

Need a little help

Started by herbertjackson, May 24, 2013, 07:27:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

herbertjackson

Need a little help. Maybe I'm missing something.
I am writing a micro to make a star symbol. The circle is the diameter of the star. The lines P1 through P5 are made with the POINTPOLAR command.  The idea is to make different size stars ever time the micro is run.  The layout below is for a 5 pointed stair.   I also want the micro to make a 4, 6, 8 and 12 sided star.
My problem is how do I locate the points P1 through P5 I do not want to go through a lot of calculations to get there.   Line snap, gravity snap will not work because I cannot be sure which line it will snap to.
What I need after using the POINTPOLAR command is a "GET LAST POINT X,Y,Z" command
The idea is to locate P1, then P3 and draw a line. The locate P5 and draw a line from P3 to P5, etc.


Lar

Assuming you want to start with line P1 (vertical, from center): draw P1 the radius of the circle... use sys(9) to select P1... set a handle at the center of the circle (which will be the inner point of P1)... 'Circular Array' P1 the number of points you want with 'angle'=360.

Lar

samdavo

#2
Herbert - thanks for your macro on drawing that data table btw.

As for your problem here, I enclose
a)  a macro I found in sample macros ( I think? - not sure), called Userpoints.d3m
and which I adapted to ...
b) "diamond.d3m"  and
c) "diabox.d3m".

Basically you enter some points in ( or select something in my case)
Firstly herewith Userpoints.d3m  - maybe I've twigged it a bit, since I notice I call it Userpoints2 - but you're gonna change it anyway :):-

' UserPoints.d3m - Prompts user for up to 10 points, or maybe 30 -
' say 10 to be safe; stores
' the points in an array, then uses those points to draw a line.

' Allocate storage for the points.
Dim X(30), Y(30), Z(30)
npts = 0

Sys(41) = 1 'Set the RubberBand type to show a line.

'Prompt the user to set up to 30 points.
SetPoint "Set up to 30 points for a line; press Enter to stop." 10
npts = Sys(1)
Message "You set ", npts, " points."

Sys(41) = 0 'Turn the RubberBand back off.

' Store the points in an array.
For i = 1 To npts
    PointVal X(i) Y(i) Z(i) i
Next i

Sys(1) = 0  ' Clear the points.

'Draw a line using the points.
>Line
{
    For i = 1 to npts
       <PointXYZ [X(i), Y(i), Z(i)]
    Next i
    }

End


and herewith diamond4.d3m:-

' Diamond4.d3m - start with a selection, this calculates 6 points
' centres of bounding box faces PLUS the
'geometric centre,  records the points in an array, then draws a line.
'AND sets three handles for the solid or selection etc
'these are the centre of the diamond and midface of the top and right
'faces, as seen when looking along the z axis
'i.e the normal default direction for 2D viewing, which means it also works in 2D

' Allocate storage for the points.
Dim X(15), Y(15), Z(15)

Message "You should have something selected - ideally a 3D solid (or 2D shape)
' - this will draw a diamond in bounding box, with axes similar to the resizing handle"

X(1) = (sys(196)+sys(198))/2 'A top dead centre
Y(1) = sys(199) 'A top dead centre
Z(1) = (sys(200)+sys(201))/2 'A top dead centre

X(2) = sys(196)'B left dead centre
Y(2) = (sys(197)+sys(199))/2 'B left dead centre
Z(2) = (sys(200)+sys(201))/2 'B left dead centre

X(3) = (sys(196)+sys(198))/2 'C btm dead centre
Y(3) = sys(197) 'C btm dead centre
Z(3) = (sys(200)+sys(201))/2 'C btm dead centre

X(4) = sys(198)'D right dead centre
Y(4) = (sys(197)+sys(199))/2 'D right dead centre
Z(4) = (sys(200)+sys(201))/2 'D right dead centre

X(5) = (sys(196)+sys(198))/2 'A top dead centre
Y(5) = sys(199) 'A top dead centre
Z(5) = (sys(200)+sys(201))/2 'A top dead centre

X(6) = (sys(196)+sys(198))/2 'E front dead centre
Y(6) = (sys(197)+sys(199))/2 'E front dead centre
Z(6) = sys(200) 'E front dead centre

X(7) = (sys(196)+sys(198))/2 'C btm dead centre
Y(7) = sys(197) 'C btm dead centre
Z(7) = (sys(200)+sys(201))/2 'C btm dead centre

X(8) = (sys(196)+sys(198))/2 'F back dead centre
Y(8) = (sys(197)+sys(199))/2 'F back dead centre
Z(8) = sys(201) 'F back dead centre

X(9) = (sys(196)+sys(198))/2 'A top dead centre
Y(9) = sys(199) 'A top dead centre
Z(9) = (sys(200)+sys(201))/2 'A top dead centre

X(10) = sys(196)'B left dead centre
Y(10) = (sys(197)+sys(199))/2 'B left dead centre
Z(10) = (sys(200)+sys(201))/2 'B left dead centre

X(11) = (sys(196)+sys(198))/2 'E front dead centre
Y(11) = (sys(197)+sys(199))/2 'E front dead centre
Z(11) = sys(200) 'E front dead centre

X(12) = sys(198)'D right dead centre
Y(12) = (sys(197)+sys(199))/2 'D right dead centre
Z(12) = (sys(200)+sys(201))/2 'D right dead centre

X(13) = (sys(196)+sys(198))/2 'F back dead centre
Y(13) = (sys(197)+sys(199))/2 'F back dead centre
Z(13) = sys(201) 'F back dead centre

X(14) = sys(196)'B left dead centre
Y(14) = (sys(197)+sys(199))/2 'B left dead centre
Z(14) = (sys(200)+sys(201))/2 'B left dead centre

X(15) = (sys(196)+sys(198))/2 'diamond centre, average of min and
' max X values in the selection
Y(15) = (sys(197)+sys(199))/2 'diamond centre, average of min and max Y values
Z(15) = (sys(200)+sys(201))/2 'diamond centre, average of min and max Z values


>Line
{
    For i = 1 to 15
       <PointXYZ [X(i), Y(i), Z(i)]
    Next i
    }


'next set three handles, at the centre and midface of the top and right 
'faces, as seen when looking along the z axis
'i.e the normal default direction for 2D viewing, which means it also works in 2D

>SetHandle
{
    <Pointxyz [x(15), y(15), z(15)]
    <Pointxyz [x(1), y(1), z(1)]
    <Pointxyz [x(4), y(4), z(4)]
  }

End

Anyway, hopefully you getthe idea.
get the points you need
"calculate" the other points
record them in an array
draw whatever you like from there.

The other option uses  "Point Polar".
I'll post that next ( still writing it :) )

prl

My turn, a Saturday morning puzzle with coffee and donut.

'Program: star.d3m (draws a star)


precision 15
input "number of points", np
if np <= 2 then
  Message "number of points must be greater than 2, routine will end"
  End
endif

input "star radius", size
setpoint "Set a point for star center" 1

if sys(1)= 1 then
   pointval x1,y1,z1 1
else
   Message "no point set, routine will end"
endif

dim px(np), py(np), pz(np), entid(np)

ang = 90 'starting angle: note 90 is vertical
div = 360/np

'determine points
for i = 1 to np
  ang = ang + div
  >line
  {
   <pointxyz [x1, y1, z1]
   <pointpolar [size,ang, 0]
  }
 
  'store the points for the last entity drawn
  entity sys(9)
  pointval x,y,z, 2
  px(i)=x
  py(i)=y
  pz(i)=z
  >eraselast
  {
  }
  sys(1) = 0
next i

'draw the star
  for i = 1 to np
    if i + 2 > np then
       j = i+2-np
    else
       j = i+2
    endif
    >line
    {
     <pointxyz [px(i),py(i),pz(i)]
     <pointxyz [px(j),py(j),pz(j)]
    }
    'store entid
   entid(i)=sys(9)
  next i

'combine the lines into fewest vectors - odd points will give one line
  for i = 1 to np
    getattr entid(i), type
    putattr entid(i), type, 1
  next i
 
if sys(80) > 0 then
   >combine
   {
   }
   sys(80)=0
endif 
 
END

samdavo

wow - thanks prl - tons of wisdom in those lines - and plenty more to study on my behalf :)

PS you think I'm gonna post my effort (whilst watching TV) after you've posted THAT, you're kiddin lol.

samdavo

#5
Hey prl, (or anyone else for that matter :) )

After you run a macro, is it possible to check what are the values of the parameters you used - or calculated .

eg,  suppose that you input some variables called
nrays = number of rays,
lenrays = length of rays

then you calculate say the angle between them
angdelta = 360/nrays,

I realise that DURING the macro you can ask it for
message "angle between rays = ", angdelta
and that gives you the info in real time...

But how about later?
where are those numbers stored?
and how do you find their values?

In your case, how about finding out all those numeric values px(I), py(I) ?
Is it possible in hindsight?

I was thinking of something like this ...  which is clearly just a mudmap...

'Interrogate-old-macro-data.d3m can be run to check stored data
Input "what variable value do you need to check?" , A$
Avalue  (or whatever that would be called)  =  val (A$) or whatever
Message  “value of” ,  A$ , “is ”, Avalue 
(?)

prl

#6
Quote from: samdavo on May 25, 2013, 04:08:59 AM
After you run a macro, is it possible to check what are the values of the parameters you used - or calculated .

If you are using odd points, it creates a single line.  So before the routine ends, dump the radius and npoints values (as strings) into the sys$(300) field for the single line.

If you are using even points, it will create two lines.  So before the routine ends, group the two lines and then dump the radius and npoints as strings into the sys$(300) field for the group.

Then select the star and use the infobox to find out the values used.

samdavo

Thanks
I'll give it a go.
Maybe after 40 days in the wilderness it will be clear to me lol.
See you in a month and a bit :)

prl

Quote from: samdavo on May 25, 2013, 06:01:01 AM
See you in a month and a bit :)

Enjoy (Zen and the Art . . . .)

herbertjackson

Thanks prl.  You wrote the program for me.

prl

#10
Quote from: herbertjackson on May 25, 2013, 06:52:02 AM
Thanks prl.  You wrote the program for me.

You're welcome. More time for brats and beer this holiday weekend.

prl

#11
Quote from: samdavo on May 25, 2013, 06:01:01 AM
Maybe after 40 days in the wilderness it will be clear to me lol.

I'm guessing 40 days from now you will not remember.  The coding you seek is in blue.


'Program: star.d3m (draws a star)

'5/25/2013 - added field data string for Sam

precision 15
input "number of points", np
if np <= 2 then
  Message "number of points must be greater than 2, routine will end"
  End
endif

input "star radius", size
setpoint "Set a point for star center" 1

if sys(1)= 1 then
   pointval x1,y1,z1 1
else
   Message "no point set, routine will end"
endif

'create infobox string
precision 4
rad$=size
precision 0
npts$=np

fs$=npts$+" pts, rad = "+rad$

precision 15

dim px(np), py(np), pz(np), entid(np)

ang = 90 'starting angle: note 90 is vertical
div = 360/np

'determine points
for i = 1 to np
  ang = ang + div
  >line
  {
   <pointxyz [x1, y1, z1]
   <pointpolar [size,ang, 0]
  }
 
  'store the points for the last entity drawn
  entity sys(9)
  pointval x,y,z, 2
  px(i)=x
  py(i)=y
  pz(i)=z
  >eraselast
  {
  }
  sys(1) = 0
next i

'draw the star
  for i = 1 to np
    if i + 2 > np then
       j = i+2-np
    else
       j = i+2
    endif
    >line
    {
     <pointxyz [px(i),py(i),pz(i)]
     <pointxyz [px(j),py(j),pz(j)]
    }
    'store entid
   entid(i)=sys(9)
  next i

'combine the lines into fewest vectors - odd points will give one line
  for i = 1 to np
    getattr entid(i), type
    putattr entid(i), type, 1
  next i
 
if sys(80) > 0 then
   >combine
   {
   }
   
   if sys(80) = 1 then
      entity sys(9)
      sys$(300)=fs$
   else
     >groupdefine
     {
     }
     entity sys(9)
     sys$(300)=fs$
   endif 


endif

   sys(80)=0

 
END

samdavo

Thanks prl,
That entity name sys$(300) contains  the two variables that you used - so far so good and certainly something I didn't know.  I'm guessing the title of an entity is limited to maybe 50 or 100 characters? 

However, I was more about trying to check what numbers a macro had used and calculated along the way - or to have them available for reference for whatever reason.

I find this string function (following on from your sys$300 idea).
As I read this, SysEx$(1) would store 100 string functions, which would be more than enough you'd think - at least for the simple macros being discussed. 

In summary, Not sure if anyone uses this function - but maybe it provides a "storage vault" for such data ?

"The SysEx$ functions are string variables that are stored in text files and are therefore remembered between DesignCAD sessions.
There are 10,000 strings available:  SysEx$(1) to SysEx$(10000)
The variables are stored in files of 100 each , as follows:-

SysStr_001.ini stores  SysEx$(1) to SysEx$(100)
SysStr_002.ini stores  SysEx$(101) to SysEx$(200)
etc to
SysStr_100.ini stores  SysEx$(9901) to SysEx$(10000)

All SysString.ini files can be cleared by running the ClearStorage$ statement with no arguments.
An individual SysStr.ini file can be cleared by running ClearStorage$ n, where n is the number in the ini file's name.  For example

ClearStorage$ 100
clears SysStr_100.ini, thereby clearing all values from SysEx(9901) to SysEx(10000).


Not urgent obviously
but any comments welcomed.
cheers sam

prl

Quote from: samdavo on May 25, 2013, 06:56:18 PM
However, I was more about trying to check what numbers a macro had used and calculated along the way - or to have them available for reference for whatever reason.

add the below as the first line of any macro and you can see the values computed.  If you use sys(800)=2, it will dump it to a file of the name of the macro using *.log as the extension,    star.log      for example

sys(800)=1

samdavo

hey that would be great.
I found that I was inputting data , and it was doing calcs and telling me it was dividing by zero (??!) which clearly meant I hadn't loaded the data properly  - just one example.
cheers