Author Topic: Dimassoc Value  (Read 8384 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 462
Dimassoc Value
« on: February 28, 2011, 09:50:16 PM »
On my drawing the "dimassoc" is pre-set to "1".
I am confused by this:

Code: [Select]
(defun c:test (/ DimAssocValue)
(initget "0 1 2")
(setq DimAssocValue (getkword "\n0, <1>, or 2: "))
(if (or (= DimAssocValue 0)
(= DimAssocValue 1)
(= DimAssocValue 2)
)
(setvar "dimassoc" (atoi DimAssocValue))
)
(prompt (strcat "\n" "DimAssoc Value = " (itoa (getvar "dimassoc"))))
(setvar "dimassoc" 1) [color=red]; <= I want "dimassoc" reset to "1" after executing.[/color]
[color=green](princ)[/color]
)

The line of "prompt" is expected to return a "2" if the user enters "2".
But in fact this is what I got after entering "2":

Quote
Command:
TEST
0, <1>, or 2: 2

DimAssoc Value = 11

What is wrong?
« Last Edit: February 28, 2011, 10:17:21 PM by MeasureUp »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Dimassoc Value
« Reply #1 on: February 28, 2011, 09:57:53 PM »
Add a closing (princ) to your code. The first 1 is your returned value and the second 1 is returned from you resetting the system variable.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #2 on: February 28, 2011, 10:10:05 PM »
Add a closing (princ) to your code. The first 1 is your returned value and the second 1 is returned from you resetting the system variable.
Sorry for the rough sketch.
(princ) does the job.

But as I said the "dimassoc" is pre-set to "1" on my drawing.
At the "prompt" line in the code, it should return "2".
Now it returns "1".
Did I miss something?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimassoc Value
« Reply #3 on: February 28, 2011, 10:17:45 PM »
Try this:

Code: [Select]
(defun c:test (/ DimAssocValue)
  (initget "0 1 2")
  (setq DimAssocValue (getkword "\n0, <1>, or 2: "))
  (if (member DimAssocValue '("0" "1" "2"))
    (setvar "dimassoc" (atoi DimAssocValue))
  )
  (prompt (strcat "\n" "DimAssoc Value = " (itoa (getvar "dimassoc"))))
  (setvar "dimassoc" 1)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #4 on: February 28, 2011, 10:28:01 PM »
Big THANKS to CAB.  :lol:
It is great.

But why my "or" statement is wrong?

I also upated the code:
Code: [Select]
(defun c:test (/ ass DimAssocValue)
(setq ass (getvar "dimassoc"))
(initget "0 1 2")
(setq DimAssocValue (getkword "\n0, <1>, or 2: "))
(if (member DimAssocValue '("0" "1" "2"))
(setvar "dimassoc" (atoi DimAssocValue))
)
(prompt (strcat "\n" "DimAssoc Value = " (itoa (getvar "dimassoc"))))
(command "dimlinear")
(setvar "dimassoc" ass)
(princ)
)

The dimension drawn is not associative when the "dimassoc" is set to "2".
What is wrong?
« Last Edit: March 01, 2011, 04:42:11 PM by MeasureUp »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimassoc Value
« Reply #5 on: March 01, 2011, 07:35:17 AM »
getkword returns string value and you were comparing the result to integers. 8-)

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #6 on: March 01, 2011, 04:45:51 PM »
getkword returns string value and you were comparing the result to integers. 8-)

Yes, it's the trick. Thanks again.  :-)
Another one is what is wrong with the updated code on Reply#4?

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #7 on: March 02, 2011, 12:38:06 AM »
The Problem has been solved.
- End of the Thread.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimassoc Value
« Reply #8 on: March 02, 2011, 08:01:44 AM »
Glad you conquered the problem.

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #9 on: March 02, 2011, 07:32:08 PM »
Glad you conquered the problem.


Thanks again.  :laugh:

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #10 on: March 02, 2011, 07:41:24 PM »
I think I have to open this thread again for another question.  :oops:

This is what I have and the red is the trick for my last problem:

Code: [Select]
(defun c:test (/ ass DimAssocValue)
(setq ass (getvar "dimassoc"))
(initget "0 1 2")
(setq DimAssocValue (getkword "\n0, <1>, or 2: "))
(if (member DimAssocValue '("0" "1" "2"))
(setvar "dimassoc" (atoi DimAssocValue))
)
(prompt (strcat "\n" "DimAssoc Value = " (itoa (getvar "dimassoc"))))
(command "dimlinear" [color=red]pause pause pasue[/color])
(setvar "dimassoc" ass)
(princ)
)

How to do if I want have a loop (while) function for "dimlinear"?
Thanks.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Dimassoc Value
« Reply #11 on: March 02, 2011, 07:47:25 PM »
Your last 'pause' is spelt wrong  ;-)

Consider perhaps something along these lines:

Code: [Select]
(defun c:test ( / ass elast )

  (setq ass (getvar 'DIMASSOC))
  (initget "0 1 2")
  (setvar 'DIMASSOC (atoi (cond ( (getkword "\nSpecify DIMASSOC Value [0/1/2] <1>: ") ) ( "1" ))))

  (prompt (strcat "\nDIMASSOC Value = " (itoa (getvar 'DIMASSOC))))

  (setq elast t)
  (while (not (equal elast (setq elast (entlast))))
    (command "_.dimlinear" pause pause pause)
  )
  (setvar 'DIMASSOC ass)
  (princ)
)

Don't worry about the capitalised System Variables, that's just a habit of mine...

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #12 on: March 02, 2011, 07:59:27 PM »
Thanks Lee.
Quote
Your last 'pause' is spelt wrong
I will check if my keys were labelled wrong.  :laugh:

A question to ask before giving your revision a try.
I notice that in your version you change all "dimassoc" to 'dimassoc.
Could you kindly explain what is the advantage(s) by doing this?
Thanks again.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Dimassoc Value
« Reply #13 on: March 02, 2011, 08:04:00 PM »
No advantage, both are equally valid - I just have my habits...  :ugly:

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #14 on: March 02, 2011, 08:15:48 PM »
Ok, I tried it.
When I stop the while function the code doesn't continue and reset the dimassoc to 1.
I preset the dimassoc to 1 before run the code.  :-(

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Dimassoc Value
« Reply #15 on: March 02, 2011, 08:37:59 PM »
how are you stopping the while loop?  if you are hitting Esc then, no, the value will not be reset since pressing Esc is considered an error. For the value to be reset when the user hits Esc you would need an error handler - there is a tutorial on my site where you can learn how to create one.

Have you tried exiting the program by pressing enter?

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #16 on: March 02, 2011, 08:41:36 PM »
how are you stopping the while loop?  if you are hitting Esc then, no, the value will not be reset since pressing Esc is considered an error. For the value to be reset when the user hits Esc you would need an error handler - there is a tutorial on my site where you can learn how to create one.

Have you tried exiting the program by pressing enter?

No, but right-click the mouse.
It equals to "enter".
« Last Edit: March 02, 2011, 09:07:05 PM by MeasureUp »

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #17 on: March 03, 2011, 12:37:22 AM »
Actually I added a line in red for testing:
Code: [Select]
(defun c:test ( / ass elast )

  (setq ass (getvar 'DIMASSOC))
  (initget "0 1 2")
  (setvar 'DIMASSOC (atoi (cond ( (getkword "\nSpecify DIMASSOC Value [0/1/2] <1>: ") ) ( "1" ))))

  (prompt (strcat "\nDIMASSOC Value = " (itoa (getvar 'DIMASSOC))))

  (setq elast t)
  (while (not (equal elast (setq elast (entlast))))
    (command "_.dimlinear" pause pause pause)
  )
  (setvar 'DIMASSOC ass)
[color=red](prompt (strcat "\nDimAssoc Value = " (itoa (getvar 'DIMASSOC)) "\n"))[/color]

(princ)
)
Again I preset the drawing with "dimassoc" to 1 and below is what I have from the textscreen:

Quote
...
Command:
_.dimlinear
Specify first extension line origin or <select object>:
Specify second extension line origin:
Specify dimension line location or
[Mtext/Text/Angle/Horizontal/Vertical/Rotated]:
Dimension text = 478
Command:
DimAssoc Value = 2
_.dimlinear
Specify first extension line origin or <select object>: <= Press "enter" here

Select object to dimension: <= Press "enter" here again



Command: <= Press "enter" again here
TEST Unknown command "TEST".  Press F1 for help.

Command:

DimAssoc Value = 1

The question is why I have to press the "enter" 3 times to stop the code running?
« Last Edit: March 03, 2011, 07:57:37 PM by MeasureUp »

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #18 on: March 03, 2011, 07:55:38 PM »
This is really frustrated.
Can anyone help please?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Dimassoc Value
« Reply #19 on: March 03, 2011, 07:59:13 PM »
Use this instead:

Code: [Select]
(defun c:test ( / ass p1 )

  (setq ass (getvar 'DIMASSOC))
  (initget "0 1 2")
  (setvar 'DIMASSOC (atoi (cond ( (getkword "\nSpecify DIMASSOC Value [0/1/2] <1>: ") ) ( "1" ))))

  (prompt (strcat "\nDIMASSOC Value = " (itoa (getvar 'DIMASSOC))))

  (while (setq p1 (getpoint "\nSpecify First Point <Exit> : "))
    (command "_.dimlinear" "_non" p1 pause pause)
  )
  (setvar 'DIMASSOC ass)
  (princ)
)

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #20 on: March 03, 2011, 08:16:23 PM »
Thanks Lee.
It works now.  :-)

In the previous one you tried to compare two selected entities.
Can you explain why the previous one doesn't do the job properly?
I notice that while functions works if using a defined point as the condition.
I also use this before without any problems.
Thanks again.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Dimassoc Value
« Reply #21 on: March 03, 2011, 08:29:29 PM »
The previous code didn't work because the DimLinear command has a default option "<Select Object>" that was being selected when the user pressed Enter.

If this default option didn't exist, the previous version would have worked as well.

FYI: I was not comparing two 'selected entities', I was comparing the last entity created in the drawing database before the DimLinear command is called with the last entity created after the command is called. The While condition would only continue if such entities differed, hence if the DimLinear command successfully added an entity to the drawing database.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimassoc Value
« Reply #22 on: March 03, 2011, 09:54:33 PM »
Yes, you are right.
Thanks for your help.  :laugh: