Author Topic: Dimassoc Value  (Read 8383 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.  :-(