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.

Is there a way to use a data and read statement in CADBasic?

Started by Rodney, March 08, 2010, 12:01:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rodney

In most basic languages, you can have a list of data points then read them later.  for instance, put in several x,y coordinates in a data statement then read them later and draw a circle at each set of coordinates.  Can CADBasic do this?  For instance, while in 2D mode use the following macro:

data 3,3,8.5,3
dia = 0.2
for i = 1 to 2
>circle
{
read x,y
>pointxyz x,y
>pointrel 0,dia
{
next i

Bob P

As far as I know, there isn't any "data" way to input a variable within a macro.  It would normally be done with an external file.  Go here and download the macro help files.  Things haven't changed too much from V17.  Maybe someone else here can volunteer something more recent.

You will use "Open" to grab sequential points from the file.  Generally it's easier to put groups of values (x,y) on separate lines in the data file.

Dempsey

V17 macro documentation is the latest. We are all waiting for the V20 macro documentation.
Dempsey

DrollTroll

You should be able to use dimensions in a similar, though somewhat less convenient, way.

Dim X(2)
Dim Y(2)

X(1) = 3
Y(1) = 3
X(2) = 8.5
Y(2) = 3

rad = 0.2

For i = 1 to 2
>Circle
{
<Pointxyz [X(i), Y(i), 0]
<PointRel [0, rad]
}
Next i

Another possibility is to store the data in a file, and read it from the file.
25 years with DesignCAD

Lar

Here is my version. I had the basis for this macro developed already in a multi-line text macro and I had to do a bit more tinkering to adapt  it for this purpose.

For your own implementations you would only need to change the numbers within the quotes in the data$ line, and the stuff within the asterisks, except the "gosub" line and the "END" line. Generally, though, everything must remain in their current location for the macro to work.

Lar
ps: if you use variabls other than x and y you would have to revise them in the subroutine section.

'****MacroStart*****
'Data String, LAR style.d3m
'Macro to emulate data string function not present in BasicCAD
'by Lar, Nassau, Bahamas,
'12 Mar, 2010

data$="0,0,0,1,0,2,0,3,1,0,2,0,4,0,4.5,1,5,2,5.5,3,6,2,6.5,1,7,0,5.5,1,9,0,9,1,9,2,9,3,10,1,10,3,11,1.5,11,2.5,10.5,.5,11,0,11.5,-.5"

LEN_data=LEN(data$)
coma$=","
coma1st=INSTR(data$,coma$)       'position of 1st comma in data$...
comaR=LEN_data-coma1st            'length of everything after the 1st comma, to be used in the RIGHT$ statement. This would become the new data$
'********************************************
dia=0.3
for i=1 to 25
gosub findXY

>circle
{
<pointxyz [x,y,0]
<pointrel [0,dia]
}
next i

END

'********************************************
'SUBROUTINE
findXY:
x$=LEFT$(data$, coma1st-1)
x=VAL(x$)
data$=RIGHT$(data$,comaR)        'data$ now equals rightmost characters after 1st comma...
LEN_data=LEN(data$)                  'new length of data$...
coma1st=INSTR(data$, coma$)     'position of new 1st comma...
comaR=LEN_data-coma1st           'new rightmost length after 1st comma...

if coma1st=0 then    '...when no more commas, ie, at last number (if user ends data$ with a comma should still workout, I think)
y$=(data$)              'without this, when no more commas "coma1st-1" won't evaluate correctly...
else
y$=LEFT$(data$, coma1st-1)    'goes here until just before no more commas, ie, the number before the last...
end if

y=VAL(y$)
data$=RIGHT$(data$,comaR)   'same comments as above...
LEN_data=LEN(data$)
coma1st=INSTR(data$, coma$)
comaR=LEN_data-coma1st

RETURN
'****MacroEnd******

herbertjackson

Yes you can put data in a file and read it with the open and input commands.
I have down this with steel programs to draw beams and angles

herbertjackson

Rodney, I will E-mail you one MICRO and one DATA file as an example on how to draw steel channels. Both of these files must be put into the same directory folder.
After you put the file where you want them. Put a point any where on the screen and run the CHANNEL micro.  Type in the channel size as one word. An example of some sizes would be c8x11.5,  c10x30,  c15x50,  mc12x10.6,  mc12x50.
You may use capitals or small letters.
The channel program will search the data file, if it fines a match, it will draw the proper structural channel.  If  you typed the input wrong it will flash a message saying it did not find it.
You can use this as an example on how to retrieve data from an external file.  If I put the files on this forum it may get messy with the long data file.

Herb jackson

Rob S

Herb

Any chance you might share this on the forum for other designcad users as well.

I would certainly find it useful.
User since forever

herbertjackson


Pearco

Herb;

When you create a post, just below and to the left of where I am typing this reply is Additional Options. That will lead you to where you can add items.
Jim
User since ProDesign 1.5

herbertjackson

here you go Rob.  See post 118 under BasicCad on how to use this.
I choice the Channel micro because it's the shortest one I have.
I also have structural shapes and structural angle shapes if any one is interest.