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.

Testing *.d3m files

Started by wgwade, April 26, 2011, 12:51:30 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

wgwade

In one of the old Designcad books was a program to test *.d3m files, before using them in DesignCad. I think it was called "ptest". I would like to get a copy of this program. Thank you Bill.

paulerens

P.test does not exist in the macro examples, but what would you like to find.
We can probably help!

Bob P

You have a good memory... Ptest.exe was a program for DC DOS.  AFAIK, nothing like it for Windows macros, where error checking is built in.  You can put pauses in between actions so that you can step through your macro though.

DrollTroll

There's the Sys(800) function, which allows you to see the results of your macro as it is being executed.
Sys(800) = 1 is on-screen only, but Sys(800) = 2 will dump the results to a text log file. That's  helped me sort out a bunch of logic errors.

For simpler debugging, just inserting a simple Message statement can often help. For example, if you want to check the value of i at a particular point in the code use something like
Message "i: ", i

However there's no Ptest-like program to let you test your macro outside of DesignCAD. Macros can only run from within the program now.
25 years with DesignCAD

Dempsey

If you like you can install the free PsPad editor and customize it for BasicCAD macro editing.

prl had all this customization published in the old forum. I have attempted to republished the info in http://forum.designcad.com/index.php?topic=3373.0. The nice thing about it is that after you have edited and saved a macro you can then run it against an open drawing by pressing F9 in PsPad. However, when you press ALT-F9 it automatically insert Sys(800)=1 temporarily and a debug window is opened to look at the results. I typically insert Sys(800)=1 and Sys(800)=0 around a critical part of the macro where I suspect a problem is.
Dempsey

DrollTroll

Yes, I use PSPad almost exclusively for all my BasicCAD scripting.
25 years with DesignCAD

Dempsey

DT,

Sorry, my above reply was actually intended for wgwade, but thanks for putting in a good word for PsPad.  ;D
Dempsey

wgwade

Thank you one and all, I am OK now. Regards Bill.

wgwade

I inserted sys(800)=1 in my macros. Please look at the log file. What am I doing wrong when it is showing FALSE ?.
[1] - C:\Users\William Wade\Documents\DesignCAD 3D MAX 20\octahedron.d3m
=== Start Tracing ======>
[1:3] - sys(130)=5   ---> 5.0000
[1:4] - sys(131)=5   ---> 5.0000
[1:5] - print" (1)   spherical"   --->  (1)   spherical
[1:6] - print" (2)   elliptical (profile)"
   --->  (2)   elliptical (profile)
[1:7] - print" (3)   super-spherical (profile)"
   --->  (3)   super-spherical (profile)
[1:8] - print" (4)   super-elliptical (profile)"
   --->  (4)   super-elliptical (profile)
[1:9] - print" (5)   super-elliptical (plan - profile)"
   --->  (5)   super-elliptical (plan - profile)
[1:12] -      INPUT"type of dome (1-5)",td
[1:13] -      td=int(td)   --> 1.0000
[1:14] -      IF td<1 OR td>5 then goto 310   ---> FALSE
[1:17] -      INPUT"frequency of dome (1-32)",f
[1:18] -      f=int(f)   --> 1.0000
[1:19] -      IF f<1 OR f>32 then goto 330   ---> FALSE
[1:20] -      ff=int((f^2-f)/2+f)   --> 1.0000
[1:21] -  pe=1        --> 1.0000
[1:22] -      fe=1   --> 1.0000
[1:23] -      IF td = 1 then goto 520   ---> TRUE
[1:36] -      sys(36)=1   ---> 1.0000
[1:37] -  sys(33)=1   ---> 1.0000
[1:38] -  precision 4   ---> 4
[1:39] -  DIM x(3,ff),y(3,ff),z(3,ff)
[1:40] -      a=1.5707963275   --> 1.5708
[1:41] -      n=2   --> 2.0000
[1:42] -      IF td =1 OR td=3 then f1=950    ---> TRUE
   --> 950.0000
[1:43] -      f2=f1*1.06   --> 1007.0000
[1:44] -      IF td =2 OR td =4 then goto 560   ---> FALSE
[1:45] -      ELSE 570

paulerens

#9
Quote
[1:44] -      IF td =2 OR td =4 then goto 560   ---> FALSE



Since td is not 2 or 4, the condition is not met and is-----> false

DrollTroll

wgwade, I think BasicCAD is quite a bit less sophisticated than you are expecting it to be.

In the absence of a window, your PRINT statements at the beginning are going to be printed to the status bar, one at a time, so only the last one will be visible by the time the Input statement pops up.

Your Dim commands on line 39 are unlikely to work as expected. DesignCAD only does single-dimensional arrays, based at 1. Thus your multi-dimensional statements at label 1480 and later will not function as you intend.

Your If/Else statements are not structured so that DesignCAD will understand them. If you put anything after THEN on the same line, that is treated as a standalone IF statement. Any statement below it will be treated as a statement that should be run unconditionally. Any time you've got a THEN associated with your IF, put

IF condition THEN    ' IF THEN on a single line
  'followed by all statements to be executed if condition is true
  Statement 1
  Statement 2
  etc.
ELSE ' ELSE on a single line by itself
  'followed by all statements to be executed if condition is false
  Alt Statement 1
  Alt Statement 2
  etc.
END IF    'always close multi-line IF statements with an END IF statement (even if there's not an ELSE)

Example 1 (lines 44-45):
     IF td =2 OR td =4 then goto 560
     ELSE 570
should instead be structured like this:

     IF td =2 OR td =4 THEN
        GOTO 560
     ELSE
        GOTO 570
     END IF
(NOTE: the capitalization doesn't actually matter, but it's much easier to read and debug BasicCAD if you are consistent with how you case the built-in keywords)

Alternate example of a single-line IF statement
IF condition THEN single statement 'requires no END IF

'multi-line IF statement
If Sys(999) Then
  Message "User pressed Esc or Cancel"
  End
Else
  Message name$
End IF
End

Perhaps while you are getting familiar with BasicCAD's foibles and limitations, you should try implementing your macros in smaller stages. This is a really ambitious starter project for BasicCAD!

First I'd suggest you work out the input stage, and use MESSAGE statements liberally (or Sys(800)) to verify that you are getting and understanding all the user's input.

Then stub in the remaining stages a bit at a time, stubbing in the remainder of cases with END or Message statements.

25 years with DesignCAD

Lar

#11
NOTE: DT and I were replying at the same time and he beat me to the punch but I'll post my reply anyway, plus I inserted my edited code...

wgwade,

I edited your code. My edits are flush to the left so you can notice them. I also put in values for those asked for in the macro (for testing sake). The sys(800)=1 slows the running way down so I commented that out.

There were a bunch of 'if-then-else' situations that had the wrong syntax. Once I got past those I ran into values in brackets with commas in them, such as (1,j), so I got rid of the '1,' part. This also applied to DIM statements. I'm not sure what your intention was but I just cleared them up so the macro would run. This also applies to the '<POINTXYZ [xx,xy,0,yx,yy,0]' stuff near the end, which I made '<POINTXYZ [xx,xy,0]'.

Another good idea is to add comments as to what sys values mean, for your own sake.
For example,
if sys(80)=0 then  'if nothing is selected...

After all this, the good news is that the macro completed. The bad is that absolutely nothing was drawn by the time the macro completed.

Oh, I just noticed the print statements at the beginning, which I didn't see during the running of the macro because they flew by so fast, since the macro would not pause between them. It's best to put info like that in the input statement comments since the print line text is very easy to ignore. Unfortunately the input statement takes limited text...

Also, I'm not sure if the 'x(j)=' stuff is legit in 1480. Far as I know only SYS and DIM makes use of brackets like that...

Another thing: you should explain your repeats, otherwise the user may continuously put in the wrong value (even if the macro is just for you... there may be a long break between using and you will most likely forget the process)...
...for example:

310:
    INPUT"type of dome (1-5)",td
if sys(999) then end     'macro will end if the user clicks cancel...
    td=int(td)
    IF td<1 OR td>5 THEN
message "Sorry, you entered a value less than 1 or more than 5. Please try again or press Cancel to end this macro"
GOTO 310
end if


My edited code is below. You can use this to fix your own:

Lar


CLS'  Octahedron  Class 1, by w.wade  april 2011

'''sys(800)=1


sys(130)=5
sys(131)=5
print" (1)   spherical"
print" (2)   elliptical (profile)"
print" (3)   super-spherical (profile)"
print" (4)   super-elliptical (profile)"
print" (5)   super-elliptical (plan - profile)"

310:
    '''''INPUT"type of dome (1-5)",td
td=3
    td=int(td)
    IF td<1 OR td>5 THEN GOTO 310

330:
    ''''INPUT"frequency of dome (1-32)",f
f=20
    f=int(f)
    IF f<1 OR f>32 then 330
    ff=int((f^2-f)/2+f)
pe=1    
    fe=1
    IF td = 1 then goto 520

380:
    '''''INPUT"profile expansion (.5-2.0)",pe
pe=2
    IF pe<.5 OR pe>2.0 then goto 380
IF td <> 5 then goto 520

390:
    '''''INPUT"floor expansion(.5-2.0)",fe
fe=2
    IF fe<.5 OR fe>2 then goto 390


520:
    sys(36)=1
sys(33)=1
precision 4
DIM x(ff),y(ff),z(ff)

''''MESSAGE (3,ff)

    a=1.5707963275
    n=2
    IF td =1 OR td=3 then f1=950
    f2=f1*1.06
    IF td =2 OR td =4 then
goto 560
    ELSE
goto 570
end if

560:
    IF fe > pe then
f1=950/fe
    f2=(950*1.06)/fe
    ELSE
f1=950/pe
    f2=(950*1.06)/pe
end if

570:
    IF td <> 5 then
goto 590
    ELSE
goto 580
end if

580:
    IF fe > pe then
f1=950/fe
    f2=(950*1.06)/fe
    ELSE
f1=950/pe
    f2=(950*1.06) /pe
end if

590:
    j=1
FOR z=f TO 1 step -1
    FOR x1=0 TO f-z
              y1=f-(x1+z)
              z1=f-(x1+y1)
              IF x1+y1=0 then px=0
              tx=0
              GOTO 690
              IF x1=f then px=a
              tx=a
              GOTO 690
              IF y1=0 then px=a
              GOTO 680
              px=atn(x1/y1)

              680:
              tx=atn(((x1^2+y1^2)^.5)/z1)

              690:
              IF x1+y1=f then tx=a
              IF y1=f then px=0
              x2=x1 + 1
              z2=z1-1
              y2=f-(x2+z2)
              IF x2=f then py=a
              ty=a
              GOTO 750
              IF y2=0 then py=a
              GOTO 740
              py=atn(x2/y2)

              740:
              IF z2=0 then
ty=atn((x2^2+y2^2)^.5)
              ELSE
ty=atn(((x2^2+y2^2)^.5)/z2)
end if

              750:
              IF x2+y2=f then ty=a
              IF y2=f then py=0
              x3=x2-1
              z3=z2
              y3=f-(x3+z3)
              IF x3=f then pz=a
              tz=a
              GOTO 810
              IF y3=0 then pz=a
              GOTO 800
              pz=atn(x3/y3)

              800:
              IF z3=0 then
tz=atn((x3^2+y3^2)^.5)
              ELSE
tz=atn(((x3^2+y3^2)^.5)/z3)
end if

              810:
              IF x3+y3=f then tz=a
              IF y3=f then pz=0
              k=j
              GOSUB 1150
              GOSUB 1280
              GOSUB 1480
              j=j+1
         NEXT x1
    NEXT z
    GOSUB 1590
    GOSUB 2230
    GOSUB 2580
    END

1150:
    IF td=1 then n=2
    RETURN
    IF td=3 then n=2.5
    RETURN
    IF td=2 then n=2
    GOTO 1200
    IF td=4 then n=2.5
    GOTO 1200
    IF td=5 then n=2.5
    GOTO 1200

1200:
    IF tx<=a GOTO 1220
    tx=atn(tan(tx)/pe^.5)

1220:
    IF ty>=a then [1240]
    ty=atn(tan(ty)/pe^.5)

1240:
    tz=atn(tan(tz)/pe^.5)
    RETURN

1280:
    IF td=1 THEN GOTO 1290
    IF td=2 THEN GOTO 1330
    IF td=3 THEN GOTO 1380
    IF td=4 THEN GOTO 1330
    IF td=5 THEN GOTO 1430

1290:
    rx=1
    ry=1
    rz=1
    RETURN

1330:
    rx= (pe^n/(pe^n*sin(tx)^n+cos(tx)^n))^(1/n)
    ry= (pe^n/(pe^n*sin(ty)^n+cos(ty)^n))^(1/n)
    rz= (pe^n/(pe^n*sin(tz)^n+cos(tz)^n))^(1/n)
    RETURN

1380:
    rx =(1/(sin(tx)^n+cos(tx)^n))^(l/n)
    ry =(1/(sin(ty)^n+cos(ty)^n))^(l/n)
    rz =(1/(sin(tz)^n+cos(tz)^n))^(l/n)
    RETURN

1430:
    rx=((pe*fe)^n/((pe*sin(tx))^n*(cos(px)^n+(fe*sin(px))^n)+(fe*cos(tx))^n))^(1/n)
    ry=((pe*fe)^n/((pe*sin(ty))^n*(cos(py)^n+(fe*sin(py))^n)+(fe*cos(ty))^n))^(1/n)
    rz=((pe*fe)^n/((pe*sin(tz))^n*(cos(pz)^n+(fe*sin(pz))^n)+(fe*cos(tz))^n))^(1/n)
    RETURN

1480:
    x(j)=rx*sin(tx)*cos(px+a)
    y(j)=rx*sin(tx)*sin(px+a)
    z(j)=rx*cos(tx)
    x(j)=rx*sin(tx)*cos(px+a)
    y(j)=rx*sin(tx)*sin(px+a)
    z(j)=rx*cos(tx)
    x(j)=rx*sin(tx)*cos(px+a)
    y(j)=rx*sin(tx)*sin(px+a)
    z(j)=rx*cos(tx)
    RETURN

1590:
    v1=1279
    v2=1023
    FOR j=1 TO k
         xx=x(j)*f1+v1
         xy=v2-y(j)*f2
         yx=x(j)*f1+v1
         yy=v2-y(j)*f2
         zx=x(j)*f1+v1
         zy=v2-y(j)*f2
         GOSUB 2920
    NEXT j
sys(130)=5
sys(131)=5

    INPUT"press key x = end, any other key continue",a$
          if a$="x" then
end
else
goto 1740
end if

1740:
    v1=0
    v2=1023
    FOR j=l TO k
         xx=v1-x(j)*f1
         xy=v2-y(j)*f2
         yx=v1-x(j)*f1
         yy=v2-y(j)*f2
         zx=v1-x(j)*f1
         zy=v2-y(j)*f2
         GOSUB 2920
    NEXT j
    INPUT"press key x = end, any other key continue",a$
          if a$="x" then
end
else
goto 1900
end if

1900:
    v1=1279
    v2=0
    FOR j=1 TO k
         xx=x(j)*f1+v1
         xy=y(j)*f2+v2
         yx=x(j)*f1+v1
         yy=y(j)*f2+v2
         zx=x(j)*f1+v1
         zy=y(j)*f2+v2
         GOSUB 2920
    NEXT j
    INPUT"press key x = end, any other key continue",a$
          if a$="x" then
end
else
goto 2060
end if

2060:
    v1=0
    v2=0
    FOR j=l TO k
         xx=v1-x(j)*f1
         xy=y(j)*f2+v2
         yx=v1-x(j)*f1
         yy=y(j)*f2+v2
         zx=v1-x(j)*f1
         zy=y(j)*f2+v2
         GOSUB 2920
    NEXT j
    INPUT"press key x = end, any other key continue",a$
          if a$="x" then
end
else
goto 2220
end if

2220:
    RETURN

2230:
    f3=1024-(1024-f2*pe)/2
    vl=1279
    v2=1023
    FOR j=l TO k
         xx=x(j)*f1+v1
         xz=f3-z(j)*f2
         yx=x(j)*f1+v1
         yz=f3-z(j)*f2
         zx=x(j)*f1+v1
         zz=f3-z(j)*f2
         GOSUB 2940
    NEXT j
    INPUT"press key x = end, any other key continue",a$
          if a$="x" then
end
else
goto 2410
end if

2410:
    v1=0
    v2=1023
    FOR j=1 TO k
         xx=v1-x(j)*f1
         xz=f3-z(j)*f2
         yx=v1-x(j)*f1
         yz=f3-z(j)*f2
         zx=v1-x(j)*f1
         zz=f3-z(j)*f2
         GOSUB 2940
    NEXT j

2580:
    INPUT"press key x = end, any other key continue",a$
          if a$="x" then
end
else
goto 2570
end if

2570:
    v1=1279
    v2=1023
    FOR j=1 TO k
         xy=v1-y(j)*f1
         xz=f3-z(j)*f2
         yy=v1-y(j)*f1
         yz=f3-z(j)*f2
         zy=v1-y(j)*f1
         zz=f3-z(j)*f2
         GOSUB 2960
    NEXT j
    print
    INPUT"press key x = end, any other key continue",a$
          if a$="x" then
end
else
goto 2750
end if

2750:
    v1=0
    v2=1023
    FOR j=l TO k
         xy=y(j)*f1+v1
         xz=f3-z(j)*f2
         yy=y(j)*f1+v1
         yz=f3-z(j)*f2
         zy=y(j)*f1+v1
         zz=f3-z(j)*f2
         GOSUB 2960
    NEXT j
    INPUT"press key x = end, any other key continue",a$
          if a$="x" then
end
else
goto 2910
end if

2910:
RETURN

2920:
    >Line
   {
<POINTXYZ [xx,xy,0]
<POINTXYZ [yx,yy,0]
<POINTXYZ [zx,zy,0]
   }
   RETURN

2940:
    >Line
   {
<POINTXYZ [xx,xz,0]
<POINTXYZ [yx,yz,0]
<POINTXYZ [zx,zz,0]
   }
   RETURN

2960:
    >Line
   {
<POINTXYZ [xy,xz,0]
<POINTXYZ [yy,yz,0]
<POINTXYZ [zy,zz,0]
   }
   RETURN