News:

Please note new Forum URL: forum.designcad.com

Main Menu

SaveAs acts like Save

Started by Gymbo, June 13, 2019, 10:12:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Gymbo

I have 2 macros that perform basically the same function, using >SaveAs works just fine with one but the other brings up the Save As file dialog.
>SaveAs
{
<Filename [fname$]
}


I traced the problem down to a PutAttr statement, the one that saves:
PutAttr j , 13, 0, 2
and the that doesn't save:
PutAttr j , 13, 0, 2, 0, 0, 0, 0, 0

The first one, the one that saves the file, changes the color of the text to black, as does the second one, however when I change the second one like the first one, it saves the file but the text color stays the same, not black.

To make matters even more complicated both macros operate on different drawings.

Any ideas?
Regards,

Jim

Lar


I thought the purpose of >SaveAs was to open the dialog box. Far as I know it even opens the dialog when you put a filename in the code.


When the SaveAs dialog opens it's usually because the filename is missing or invalid for the >Save command.  You have to make sure fname$ is being given a value, or if there is a folder in the filename it exists, or there are no invalid characters. Also, the filename usually has to end with a backslash.


When not running a macro, SaveAs always acts like Save when the file is being saved for the first time, meaning the dialog box opens.


When you say both macros operate on different drawings  do you mean they each only work properly on a certain drawing?


Lar

Gymbo

Quote from: Lar on June 13, 2019, 07:56:42 PM

I thought the purpose of >SaveAs was to open the dialog box. Far as I know it even opens the dialog when you put a filename in the code.
Not in this case.

QuoteWhen the SaveAs dialog opens it's usually because the filename is missing or invalid for the >Save command.  You have to make sure fname$ is being given a value, or if there is a folder in the filename it exists, or there are no invalid characters. Also, the filename usually has to end with a backslash.


When you say both macros operate on different drawings  do you mean they each only work properly on a certain drawing?

Both macros were designed to work on their own drawing, they go through the drawing and replace letters with numbers, the first one replaces 16 letters while the second one replaces 19. I'm happy to share the drawings, the macros and the .txt files that hold the numbers.

These are based on some puzzles I saw in the fall issue of "Popular Science" magazine. They're kinda simple puzzles but fun for my grandkids.
Regards,

Jim

Lar

Well, you have me curious now. Let's see the whole package. I think I downloaded one of the macros from another post (but it's gone now).

Gymbo

Ok, these macros are somewhat different from the one from the other post.
Regards,

Jim

Gymbo

I decided to get to the bottom of the SaveAs macro command. I wrote a simple script to test SaveAs as well as the PutAttr Statement. The drawing, attached, consists of 10 letters,  A - J (not black). This is the script:
'Test PutAttr
'4/11/2020
dim num(10)
INCLUDE "dcadalias.d3i"
Precision 0
for i = 1 to 10
num(i) = i
next
i = 1
FOR J = 1 TO 10
    getAttr j, type, select, laynum, group, red, green, blue, solid
    entity j
    ltr$ = sys$(1)
    if ltr$ = "C" then
        a$ = j
        fname$ = "Test_" + a$ + ".DCD"
        goto here 
    end if     
    if ltr$ = "B" or ltr$ = "D" or _
        ltr$ = "F" or j > 7 then
            PutAttr j, 13, 0, 2, , 0, 0, 0  'works as advertised
            'PutAttr j, 13, 0, 2, 0, 0, 0, 0  with group = 0 won't save
            'PutAttr j, 13, 0, 2, , 0, 0, 0, 0  with solid = 0 won't save
    end if
a$ = num(i)
i = i + 1
here:   
    Change T_Text, a$
    update
NEXT
sys(3) = 2
layer(3) = 0
>FitToWindow
{
}
path$ = "D:\"
fname$ = path$ + fname$
>saveAs
{
    <filename [fname$]
}
end

Conclusions are included in the script.
Regards,

Jim

DrollTroll

Hi Gymbo,


I think the problem may be occurring because BasicCAD no longer likes blanks for fields in PUTATTR, and I'm not entirely sure it will still tolerate missing fields at the end (like skipping the solidid field at the end).


So if you want to specify a GroupID of zero, but leave the SolidID alone, use this:
PutAttr j, 13, 0, 2, 0, 0, 0, 0, solid '(you retrieved the solid ID in GetAttr above)


Similarly, if you want to specify a SolidID of zero but leave the GroupID unchanged, use this:
PutAttr j, 13, 0, 2, group, 0, 0, 0, 0


Bottom line: to be on the safe side, always specify SOMETHING for all nine fields. Ambiguity is your enemy.
25 years with DesignCAD

DrollTroll

#7
Disregard previous -- well, it's generally good advice, but may not always work in this case, and it seems at least initially you were trying that.


What did seem to work for me -- setting Sys(1174) to zero before the SaveAs command.


Sys(1174) is a sticky setting that, if set, tells DesignCAD to always pack group ids and solid ids before saving. However, if set it seems to interfere with some Save operations in BasicCAD.


From the "BasicCAD Changes and Additions PDF:

Sys(1174)
Automatically pack Group IDs and Solid IDs on Save. [0 = no, 1 = yes]. This setting remains sticky
between sessions. IMPORTANT NOTE: Sys(1174), when set to 1, is currently conflicting with some
Save operations within BasicCAD. We suggest for now that if your macro is going to save a drawing,
your macro code should set Sys(1174) to zero and use the >PackGroupIDs and
>PackSolidIDs commands (if so desired) before saving a file.
25 years with DesignCAD

Gymbo

Thanks DrollTroll, Sys(1174) seamed to work with the samples, but using your advice I added
getAttr j, type, select, laynum, group, red, green, blue, solid and PutAttr j, 13, 0, 2, group, 0, 0, 0, solid to a more complicated script and drawing and received a Failed to save document error.

Could find no info on the >PackGroupIDs or >PackSolidsIDs commands other than in the "BasicCAD Changes and Additions" PDF that you pointed out, in fact I placed them in the sample script and got an error:


It really isn't a big deal, by changing the PutAttr arguments I can get DesignCAD to open the SaveAs dialog so it's easy to save the file  after running the macro.
Regards,

Jim

bdeck

#9
Hi Gymbo,

I see the error you described. Thanks for the heads up

From my tests, SaveAs appears to be broken.

It never shows a file select dialog or a file replace dialog, unless run without parameters.

Because it never shows a file replace dialog, it will always fail the second time you try to save the same file name, unless you save using the "bak" extension.

If you use the "bak" extension, the bak file will be saved in ascii/integer format, regardless of the format of the existing file.  And the window name of the existing floating point file will show an ascii extension, even though it may still "save" as a floating point dcd file.

Putattr does not force a saveas dialog.

The "<incomplete" parameter does not force a saveas  dialog.

The command should be fixed at least to recognize the incomplete parameter, and to save bak files as the format of the original.

Stay well
bd

PS: Are you now saying that saveas opened a dialog with a filename parameter?

''' satest.d3m
'4/28/2020

'changed drawing using putattr will not trigger saveas dialog
  j=1
  rr=rr+50
  if rr>200 then rr=50
  getAttr j, t, sel, laynum, grp, red, green, blue, sol
  putAttr j, t, sel, laynum, grp, rr, green, blue, sol   

sys(36)=0    ' has no effect except to show error message
Sys(1174)=0  ' has no effect

>saveAs ' no dialog unless you leave out the filename
{
   <incomplete    ' has no effect, will not force a dialog
  'Except bak files, SaveAs will fail on second attempt to save a file to the same name because it has no error dialog
    <filename "Test12.bak"         'always works , but saves only as ascii/integer files, not Floating point
   '<filename "Test12.dcd"         'without a path, writes only to the folder of the macro, but only once
   '<filename "c:/Test12.dcd"      'fails if I write to c:/ root directory without admin priveledge (win 10)   
   '<filename "c:/dc/Test12.dcd"   'ok if I add a folder to the path (win 10), but only once
}

end






Gymbo

QuotePS: Are you now saying that saveas opened a dialog with a filename parameter?

No, I tried several ways to get it to do that but they all failed, the best thing to do is run SaveAs without the dialog.
Regards,

Jim