Author Topic: persistent scratch variables  (Read 2595 times)

bdeck

  • Hero Member
  • *****
  • Posts: 827
persistent scratch variables
« on: March 07, 2015, 12:34:46 AM »
Is there any way to attach a persistent scratch variable to a drawing file, rather than put it in a sysexXXX.ini file.

If not, there should be.

Also, the variables should be identifiable by unique names assigned by a macro, and not just by indices to prebuilt arrays, as in the sysex files.

That way one macro would be unlikely to walk on the variable space of another.

bd
« Last Edit: March 07, 2015, 02:41:23 AM by bdeck »

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: persistent scratch variables
« Reply #1 on: March 07, 2015, 01:13:59 AM »
Bd, you could put some micro text holding the variable name and value combo, example Bolt3Count=23, on some hidden and reserved layer that is always off layer, say 1999.  Then your basiccad routine would search and parse only the text on that layer for the variable name and appropriate scratch variable value.

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: persistent scratch variables
« Reply #2 on: March 07, 2015, 01:18:00 AM »
Another possibility, remember all entities can have a "Name" which is just a string.  sys$(300).  You could create a junk entity, say a line, or pointmark, or anything  on layer 1999 and have that "name" string contain all your values say separated by commas, or white space, etc.

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: persistent scratch variables
« Reply #3 on: March 07, 2015, 01:23:30 AM »
Another possibility, assuming you don't use many layers, is simply to use hidden layer names to store your string.  So if you had 50 special variables, you would have 50 special named layers, say always from 1901 to 1950,

Example:

your variable is Bolt3Count with a value of 23.    So you create a layer, say 1901, named Bolt3Count=23.  Your basiccad creates and looks for the special values while only cycling the layer names from 1901 to 1950. 


bdeck

  • Hero Member
  • *****
  • Posts: 827
Re: persistent scratch variables
« Reply #4 on: March 07, 2015, 02:27:17 AM »

prl,

I had thought that  maybe using sysex$() to hold a variable name. whose index could then be used to find the variable value in sysex() would work. The dcd file name could be added to the variable name sysex$() holder. That would work, but the data would not travel with the file, as in your examples.

Now you've got me thinking. How's this....?  Rather than hidden layers or hidden entities, perhaps a uniquely named uninstantiated block could be used to hold variable data in string form or as drawing entities having measurable dimensions. And all without fear of stepping on anyones toes.

Its crazy but it just might work....

Thanks,

bd

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: persistent scratch variables
« Reply #5 on: March 07, 2015, 05:03:53 AM »
perhaps a uniquely named uninstantiated block could be used to hold variable data in string form . . . without fear of stepping on anyones toes.

bd,  very creative!  I just tried it.  Seems to work for me.  I'll stick that in my tricks bag.

bdeck

  • Hero Member
  • *****
  • Posts: 827
Re: persistent scratch variables
« Reply #6 on: March 07, 2015, 07:51:08 AM »
Prl,

How did you do it?
I've been playing around with v 23, and cannot seem to suppress the block-insert dialog using sys(36).
Had planned to just insert the exploded block, query the text or entity values, then delete. Not so simple.

bd

EDIT:
Aha, I had neglected to use the special block insertion parameter:
<WaitForOK w - optionally displays the dialog box   [0=no, 1=yes]

Set parameter to zero, all is well,  .... but wait...
Attempt to insert a nonexistent block causes insertion of the most recently inserted block.
Must check  block for authenticity after insertion. 
Also must set sys(36) = 1 or 2  to suppress error message if no blocks exist at all.
« Last Edit: March 07, 2015, 09:47:25 AM by bdeck »

dcadRob

  • Hero Member
  • *****
  • Posts: 688
Re: persistent scratch variables
« Reply #7 on: March 09, 2015, 08:42:31 AM »
You can save info in User Notes (the text block which appears in 'drawing info')

Access in BasicCad with :

>SaveUserNotes
>LoadUserNotes

http://forum.designcadcommunity.com/index.php?topic=1237.msg6210#msg6210
« Last Edit: March 09, 2015, 08:44:39 AM by dcadRob »

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: persistent scratch variables
« Reply #8 on: March 09, 2015, 10:48:57 AM »
Forgot about this.  Apparently you can store a fair amount, although you can't get to the "User Notes" data directly from within BasicCAD.  Using BasicCAD you need to save to disk and read the data back in.  Did I get this right?

dcadRob

  • Hero Member
  • *****
  • Posts: 688
Re: persistent scratch variables
« Reply #9 on: March 09, 2015, 01:39:22 PM »
Sort of right. The commands that move the notes to and from the DCD file are basicCAD commands but there is no OLE access.

Procedure : Dump the notes to a text file. Read the file. Manipulate the text. Write out a text file. Load the text file into notes.

All of that can be done in basicCAD.

bdeck

  • Hero Member
  • *****
  • Posts: 827
Re: persistent scratch variables
« Reply #10 on: March 09, 2015, 03:48:51 PM »
dcadRob,

Thanks for the link. Had not seen that.
Informal options abound.

Regards,
bd

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: persistent scratch variables
« Reply #11 on: March 10, 2015, 06:10:45 AM »
Hmm, looked into dcadRob's comment.  I dislike having to write to disk and reading back just to get to the data.

Another option I've been playing with is using attributes.  They can easily be seen or hidden sys(21) and you can store both string text (say for variable name) and numeric value (put the numeric data in the angle or text size properties or both for two values), plus you have an additional string field, sys$(300).

It would let you do something like this which emulates OOP programming concepts.

Have the text field contain "Door" and then

Door.Width (put the width data in the text size)
Door.Height (put the height data in the angle size)

And since it is an entity, you can easily select them all (without processing the entire drawing database) by using >EntitySelect and only processing attributes.  Do some flagging with "text" content and say a color or layer, and you can quickly locate your stored variable data.
« Last Edit: March 10, 2015, 06:25:09 AM by prl »

bdeck

  • Hero Member
  • *****
  • Posts: 827
Re: persistent scratch variables
« Reply #12 on: March 10, 2015, 07:46:39 AM »
Hi Prl,

User notes not the best solution for this application, but good info to have.

Cool use of the extra text field in the attributes.

I had taken a look at attributes also, but could not find any use for them unless they are included in a block.

What I like about blocks for this application is that information in blocks can be stored and retrieved by name without affecting the drawing or the selection set.  To retrieve, just archive sys(9), insert the exploded block, query the new entity(s), then eraselast until sys(9) is correct again.

Is it possible to query the attributes in a block without first exploding the block?

bd

EDIT:

Aha, yes it is, using these parameters..

SY_ATTDEFCOUNT
SY_ATTDEFTAG
SY_ATTDEFVALUE

Big improvement. Thanks.
« Last Edit: March 10, 2015, 10:29:01 AM by bdeck »

bdeck

  • Hero Member
  • *****
  • Posts: 827
Re: persistent scratch variables
« Reply #13 on: March 10, 2015, 08:52:19 PM »
Well, on further review, while data from attributes in blocks can be read simply without disrupting the selection set, putting the attribute(s) into the block is a bit trickier, but but not impossible.

One way to do it is to open a new drawing ( >New{} ), create the attribute(s) and block in the new drawing, select the block, copy it to the clipboard, close the new drawing, and paste the block into the original drawing without selecting it. Then eraselast.

That leaves an uninstantiated block in memory as part of the original drawing file, and the original selection set is still in tact.

bd





paulerens

  • Hero Member
  • *****
  • Posts: 915
Re: persistent scratch variables
« Reply #14 on: October 16, 2015, 01:47:15 PM »
BD,
I'm a little late, but this is a good ide.