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 Help with INCLUDE for variable setting

Started by ablincoe, March 16, 2014, 07:04:56 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

ablincoe

I have tried and tried to get the  INCLUDE  to function with a file that sets variables and resides in the "drawing file" directory.  The following does not seem to work

MACRO  -  a.d3m
DRAWING_NAME$   = LEFT$(SYS$(2), LEN(SYS$(2)) - 4)
PARM_FILE$      = DRAWING_NAME$ + ".d3i"
PARM_FL = EXIST(PARM_FILE$)                     '    Is there an Include
if PARM_FL = 1  THEN                            '    Looks like it
  include       PARM_FILE$                      '       INCLUDE it
Message "VERBOSE after INCLUDE: ", VERBOSE
IF SYS(1028) = 2  THEN          GoTo  THE_END
ELSE
Message "No Parameter File found"
  END IF

THE_END:
END

INCLUDE FILE  -  DRAWING_A.d3i
PRT_TRI         = 0             '  Print Diagonal reference lines every X points
PRT_REC         = 0             '  Print perpendicular ref lines every X points
PRT_REFERENCE   = 0             '    NOT Implemented at this time
W_TOLERANCE     = .0000001      '  WARNING Tolerance violation message
                                '    .0000001 = .0063 inch devtn on 1-Mile scl
F_TOLERANCE     = .00001        '  FATAL (ABORT) Tolerance violation point
                                '    .00001 = .63 inch devtn on 1-Mile scale
VERBOSE         = 1             '  VERBOSE Setting - 0-6


None of my variables seem to get included into the original macro space.

Thanks,
Allen

ablincoe

Looks like the  -  INCLUDE  -  command will only take a static string, and not a variable to include  (darn)
     An enhancement to allow varying include file names would be nice.
The file named in the static string must also exist at the time that the macro is read in, or an error will be produced.
     It would be nicer if it did not check for the file until the time the statement is ready to execute.
The INCLUDE itself does run at the time the instruction is in the MACRO, and sets the variables without issue;
     so an include file can be used to override basic/default parameters set-up within a macro.

I'll keep my eye out here for other updates, but I think the above are all the answers that are there.

Allen

prl

Quote from: ablincoe on March 16, 2014, 11:15:14 PM
Looks like the  -  INCLUDE  -  command will only take a static string, and not a variable to include  (darn)

Looks like an oversight, probably something that Dt can amend easily.  Maybe you can piece together what you need using chain or call statements.

DrollTroll

#3
If your drawing directory is in a relative path to the include file directory, you can use an asterisk to start in the include folder.

Ex.
Include "*\MyDrawings\Houses\presets.d3m"

If it's on another drive or something, sorry, can't get there from here without a full path.

As for not checking for existence of the file until the statement runs, that's not possible. What DesignCAD does with macros and include files is basically store an internal version of the macro with all the contents of the include files stuffed in at their location on the original macro. SO if you you have macro1.d3m that includes inc1.d3i and inc2.d3i, macro1_in_memory.d3m contains all the contents of inc1, then all the contents of inc2, then all the contents of macro1. That's why INCLUDE statements need to be "up top".
25 years with DesignCAD

ablincoe

DrollTroll,
Thanks for the technical information.  That means I can't offer a macro initiated "Update the parameters" and have the updates copied to the static area, and then included on a single execution.

Guess I'll have to do some type of Macro re-start in order to provide this functionality.  That shouldn't be too difficult to accomplish.

Allen

prl

Allen, not sure where you are heading, but you can certainly write a macro that will write a macro and run it.

In other words, you write a macro that reads lines from A.d3m then A.d31 or whichever order you want and then creates atotal.d3m and then runs atotal.d3m.

DrollTroll

You might get better results from an OLE Automation program that configures and then runs your macro(s) on startup. The OLE Automation program, having access to the full Windows API, could read and/or store startup parameters anywhere you choose, and even hard-code those paths into some updated macro.
25 years with DesignCAD

Lar

#7
I didn't read through the entire thread so my apologies if I'm off-base but:
  You can write/append to an existing file, or create a new file from within a macro. If you write to an existing file it won't ask you if to overwrite (but you can put code to do so) so I think it's possible to overwrite an existing file before the include line... or create a new file and then follow that with the include line (of course, once the macro is run the first time the external file will thereafter exist so you'll be overwriting).

I think you can also "open" an existing file then sequentially read lines from it, if you don't want to use the include statement.

Can't remember the exact code but these are tricks you can explore. It's all explained in the macros help. Look for "open" statement and click on the links from there.

Lar
PS: just a note that before the message you need a sys(1027) message box type that has the Cancel button otherwise the default 'OK' button box will appear (unless it was already done earlier in the macro, before the sample you posted). 'OK' has a value of 1 and since this is the only button, 1028 would never equal 2.

bdeck

#8
Just did some testing and discovered that it appears to  be possible to use the INCLUDE statement conditionally.

If ax1.d3i and ax2.d3i are in the macro folder, and each assigns a value to a, then this works:

b=1
do while b>0
input "input b",  b
if b=1 then
include "ax1.d3i"
else
include "ax0.d3i"
endif
print "a = ",a
anykey
loop

BUT the following line generates an error:

if b=1 then  include "ax1.d3i"

This makes sense, because the DC literally replaces the include statement with the contents of the d3i file prior to execution. There is no way to replace the include statement in the offending line with the contents of a multi-line file. Even afile haveing a single executable line in it will generate an error when included in that line.

And the include statement should be just fine in the loop, because it is replaced prior to execution with the contents of the include file.

bd

ablincoe

I am working toward finishing my "UnFold" macro that I asked about in - "DesignCAD Unfolding - Surface Mesh Based"
As  Unfolding  can be tricky, and even trickier depending on the users Drafting style, I need to look at several options.
1)  Where within the Grid matrix should I start this UnFold process.
          There are 9 calculable answers to this  (Bottom Left, Bottom Center, Bottom Right, Center Left, Center Center, Center Right,, Upper Left, Upper Center, Upper Right)
2)  Does the flattening work/look better if you utilize the DC Row/Point sequence, or if the Tow/Point sequence is reversed
          This can make the UnFold liik like a "Fish Bone" print-out, or possibly a smaller number of "snakes" on the page
3)  Should the first triangle in each Row (pair) start with the "Vertical Side", or on the "Horizontal" flat side of the triangle
          I am also trying to think of a way to have Row-2 glue itself to the existing first Triangle/Rectangle of Row-1
4)  Do you need diagonal reverence lines on the output Rows to help you align the patterns later on
          (at what number of point intervals should these diagonal references be?)
5)  Do you need Tangental reference lines on the output Rows to help you align the patterns later on
          (at what number of point intervals should these lines be placed?)
6)  What layer should I place the flattened object onto.  It uses successive layers if multiple objects were selected
7)  Do you have a "Plane" preference for plotting the next point in each of the sequences  (I use X/Y, but who knows)
8)  Do you want warnings if the plotted points end up too far off of perfect  (normally a programming bug, but...)
          (I have it set to - .0000001  which is  .0063" on a 1-mile scale)
9)  Do you want the macro to terminate if the plotted points end up too far off of perfect?
          (I have it set to - .00001  which is  .63" on the same 1-mile scale)
10)  Logging Verbosity  -  Normally used by me for debugging the macro functionality.

My targeted process was to:
     Have the user start the Macro
     The Macro would ask if any of the parameters need to be changed from the previous run
          Allow the user to use  NotePad  (or something else)  to change the parameter file
          Save the parameters as a  -  MyDrawing_UnFold.d3i  -  file for inclusion into the Macro
               I am now copying that file back into a  Macro Static  area  (*\UnFold.d3i)  for use
     Include (Read) the updated parameter file to set the system variables
     Perform the UnFold logic based on the current/updated set of parameters


I need to update/replace the static - UnFold.d3i data file as the user may have been UnFold(ing) something else last, and thus the  UnFold.d3i  could be totally off track.
     If DrollTroll is correct in his explanation, this file has already been "read in and stored" as part of bringing up the macro at first.
     As such, I would need to get the file updated, and RE_START the Macro in order to read in the new parameters
I have not found a way to read in the   MyDrawing_UnFold.d3i  data file  to set the necessary parameters
     Input #x,  A$, B$, C  does not seem to work the way I want it to  (to gather the Variable Name into A$, the "=" into B$, and the value into C
          It is not separating the first 3 words and interpreting their types properly  -  A$ ends up being a "0" value, C ends up being the value I need
               but without A$ being set properly, the value is of no use.
     I could then use multiple comparisons on A$ to see which variable is being referenced, and set it's value according to  C
I am also having difficulty with  "RUN  NotePad.exe  MyDrawing_UnFold.d3i"  not waiting for NotePad to return focus to DC before the Macro continues

Yet another option may be to have a "Pre_UnFold" macro that deals only with getting the parameter file updated, and then later run the  UnFold  Macro to do the work.
     I haven't figured that one out yet, but we will see.

Allen

ablincoe

Minor update - I am currently a little way back using  -  DC V-19.1.  I believe that 19.0 may have been the first to include the Surface Connect/Patch logic.

prl

Allen,

Here is a sample file with respect to reading data, specifically look at the Parse statement.  Notice the input #1, a$ reads an entire line of text into the string a$, then you need to pull it apart.


' Program: survey.d3m (use file to read survey data)

'         sample input file format
'               s-55d22m-w  441.34'
'               s-26d4m-e    67.96'
'               n-68d48m-e  464.31'
'               n-34d38m-w  175.08'



now=sys(3)
'sys(36)=1 'silent mode

infile$="c:\survey.dat"

fmt$ = "%s-%s-%s %s"

Precision 15
open "i", 1, infile$

>arrow
{
  <Doublesided 0
  <Type 1
  <Pointxyz 10, 0, 0
  do while NOT EOF(1)
    input #1, a$
    Parse a$,fmt$, north$, ang$, east$, dist$
    dist = val(dist$)
    gosub computeangle
    <PointPolar [dist], [ang], 0
  loop
}

Close #1
sys(3)=now
run "SendUpdateMsg.exe"
End

'subroutines follow
computeangle:
ang = val(ang$)

if north$ = "n" and east$ = "e" then ang = 90 - ang
if north$ = "n" and east$ = "w" then ang = 90 + ang
if north$ = "s" and east$ = "e" then ang = -(90 - ang)
if north$ = "s" and east$ = "w" then ang = -(90 + ang)

return


prl

#12
Quote from: ablincoe on March 17, 2014, 03:01:58 PM
I am also having difficulty with  "RUN  NotePad.exe  MyDrawing_UnFold.d3i"  not waiting for NotePad to return focus to DC before the Macro continues

Regarding RUN, unless you are using an OLE, you're limited to option 0 and 1, see below.

QuoteSYNTAX:   RUN programname$ {, Status}

EXPLANATION:   The Run statement can be used to run another DesignCAD macro or an external program from within your macro. The following status values can be used with the RUN statement:

0 – resume the macro immediately (default)


1 – halt the macro until the focus returns to DesignCAD (This will occur even if the other program is still running! All it takes is a click on the DesignCAD window, or an Alt+Tab to switch focus to DesignCAD.)

2 – halt the macro until the OLE Automation program issues a ResumeBasicCAD command. This option should only be used when specifying a DesignCAD-based OLE Automation program in the RUN statement.

prl

Quote from: ablincoe on March 17, 2014, 03:05:54 PM
Minor update - I am currently a little way back using  -  DC V-19.1.  I believe that 19.0 may have been the first to include the Surface Connect/Patch logic.

Not sure what you mean?  Surface Connect/Patch have been around a long time, probably 20 years.

ablincoe

PRL,
Thanks for the GREAT INFOrmation.  It will make this evening's work MUCH easier.

Allen