How to Populte DCL boxes With Values From a Text File

How to Populte DCL boxes With Values From a Text File

mgorecki
Collaborator Collaborator
1,528 Views
9 Replies
Message 1 of 10

How to Populte DCL boxes With Values From a Text File

mgorecki
Collaborator
Collaborator

I have a dialog box with a lot of boxes to fill in.  I want to be able to populate the boxes (tiles) with the values saved from a previously run attempt.

The program currently creates a text file that stores the values, based on the drawing number.

The program currently can read the file based on the drawing number that was entered.

 

I have a button on the dialog box called "Load Previous" that runs a function that reads the text file and puts the values into the tiles.  I might not be doing that correctly.

This is the text in the DCL file:

: button {
    key = "loadPrevious";
    label = "Load Previous";
       action = "(LoadPreviousCAI)";
   }

The function determines the attribute name and the attribute value from the text file, then it's supposed to put that value into the tile.

(if (= attributeName "BODY_X") (set_tile "bodyX" attributeValue))

 

I'd appreciate any help on this, thanks.

0 Likes
Accepted solutions (1)
1,529 Views
9 Replies
Replies (9)
Message 2 of 10

Sea-Haven
Mentor
Mentor

If you make a list 1st of keys and attrib-values then on start up if NIL do load-keys function behind the scenes 1st. If you have already ran the dcl but want to use the data file, you would click your button to force a read of the file more than likely you may need to unload the dcl and reload so it now reads the current list of values.

 

 

0 Likes
Message 3 of 10

Moshe-A
Mentor
Mentor

@mgorecki  hi,

 

maybe this:

(if (= attributeName "BODY_X") (set_tile "LoadPrevious" attributeValue))

 

??

 

moshe

 

0 Likes
Message 4 of 10

mgorecki
Collaborator
Collaborator

Thank you for that info, but unfortunately I'm not sure how to do that.  The way the program will be used, the user will run it  and hopefully they get the desired results, if not, they'll want to run it again, but then they have to re-enter all the info again.  They would like a way to have the DCL automatically fill in with their previous values and just change the ones that needed changing.

If the button method was used, and I unloaded and loaded the DCL again, how would the program populate the fields after the DCL is reloaded?

 

0 Likes
Message 5 of 10

Sea-Haven
Mentor
Mentor

I do this all the time rembering values and putting them in correct tile 

step 1 if all varaibles nil set to default values ie read your file make say ((keyX value)..........

step2 do a foreach and set key value

step3 update the list ((keyx value).............

step4 on exit update txt file you can have a custom button Ok, OK_Cancel, OK_Cancel_Dofileexit

 

For me its page 166 of my R12 Autocad Customization manual making your own "Exit Button"  old paper copies come in handy.

 

ok_dotofile : column {
: row {
fixed_width true ;
alignment = centered ;
dotofile_button ;
: spacer { width = 2 ;}
ok_button ;
)
)

 

 This is not tested you can check for button dotofile when  (action_tile "dotofile"  OK is "accept" will try to put together an example.

0 Likes
Message 6 of 10

mgorecki
Collaborator
Collaborator

My function works in that it reads the text file, then populates the dialog box.  The problem is, after picking the "OK" button, it goes on to execute the code, but no values have been saved.  The program then crashes the first time it needs a value.

0 Likes
Message 7 of 10

Sea-Haven
Mentor
Mentor

You need an option "Resave file " thats waht I was suggesting with a custom button this could call a defun that rewrites the data file.

0 Likes
Message 8 of 10

Sea-Haven
Mentor
Mentor

You need to post code and dcl so people can look at it.

0 Likes
Message 9 of 10

mgorecki
Collaborator
Collaborator
Accepted solution

Hello,

Thanks for all your help.  I did finally figure it out.

I created a dialog box that asked if they want to populate from a previously run attempt and for the drawing number. 

The program now creates a text file in the form Attribute:Value and uses the values from the dialog box to print to the file.  If they ran the program already, then the file is created and they can use it to populate the dialog then next time.

If they choose to preload, then it goes to a function that loops through the text file and sets all the actual variables to the values from the text file.  (if (= attributeName "BODY_X") (setq unitLength attributeValue))

Then before the "action_tiles" I have commands like (set_tile "bodyX" unitLength), so the tile gets set to the string value from the text file.

The part that made it all work was in the "action_tile accept" line.

(action_tile "accept"
  (strcat "(progn (setq pkgGroupVal (get_tile \"pkgGrp_pop\"))"
          "(setq unitLength (atof (get_tile \"bodyX\")))"
          "(setq unitWidth (atof (get_tile \"bodyY\")))"
            :
            :
          "(done_dialog 1))"
  )
 )

That sets the values for the variables.

0 Likes
Message 10 of 10

Sea-Haven
Mentor
Mentor

You should not need the progn, good to hear its working.

0 Likes