Combine code to make it even better

Combine code to make it even better

djurk_haas
Advocate Advocate
2,435 Views
31 Replies
Message 1 of 32

Combine code to make it even better

djurk_haas
Advocate
Advocate

Hello,

The code below does what I want, but of course I want more:

  • How can I integrate Lee_Mac's code (and actually I want 3 digits instead of 4).
  • How can I stote the attribute value of the tag "TAPPUNT/KEERKLEP"  into a variable " tapkeer"  (to make the comment out code work)

 

(defun c:TP-change (/ ss i e tapkeer bouwdeel int)

(vl-load-com)

(if (setq ss (ssget ":S" '((0 . "insert")(66 . 1)(2 . "`*U*,TAPPUNT_CZE"))))
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)) )))
(if (Eq (strcase (vla-get-effectivename e)) "TAPPUNT_CZE")
(foreach itm (vlax-invoke e 'GetAttributes)


; (setq tap "Tappunt")
; (setq keer "Keerklep")
; (setq nrtappunt "NUMMER_TAPPUNT")
; (setq nrkeerklep "NUMMER_KEERKLEP")
; (cond ((= tapkeer tap) (setq nr nrtappunt))
; ((= tapkeer keer) (setq nr nrkeerklep))
; (t (prompt "N.v.t.: Tappunt onder/boven")))


(if (eq (vla-get-tagstring itm) "NUMMER_TAPPUNT")

(vla-put-textstring itm (getstring "\nTappuntnr: ") )))
)))
(princ)
)

 

Code van Lee_Mac:

(defun c:4digits ( / int )
(while
(and
(progn
(initget 6)
(setq int (getint "\nEnter a 4-digit number <Exit>: "))
)
(not (wcmatch (itoa int) "####"))
)
(princ "\nThat's not 4-digits!")
)
(if int
(princ (strcat "\nYou entered " (itoa int) "."))
(princ "\nUser exited.")
)
(princ)
)

 

0 Likes
Accepted solutions (2)
2,436 Views
31 Replies
Replies (31)
Message 21 of 32

djurk_haas
Advocate
Advocate

Thanks again for the service.

 

To make it even more complete, is it also possible to check whether a tapping point number has already been used in the drawing?

So when the attribute value 001 already occurs in one of the blocks thers is  a notification that it is no longer allowed. Maybe too much to ask but would be more than great.

 

 

 

I can not program a code from scratch myself. I can analyze an existing code and adjust it a little bit.
I would like to learn more about lisp, are there books or websites with exercises, etc.?
Otherwise, I will continue to bother you guys on this forum.

0 Likes
Message 22 of 32

roland.r71
Collaborator
Collaborator

Don't thank me, thank @pbejse 😉

 

As for learning lisp...

Afralisp.net still is a good starting point.

 

As for your request: That's a bit more advanced. You'll need to read all available blocks, retrieve any existing values & while asking the user for a new one, check it with the existing ones.

 

Totally possible, but it will take a lot more (programming) to get it done.

0 Likes
Message 23 of 32

djurk_haas
Advocate
Advocate

Hello thanks agian (if you know where to look it is sometimes quite easy to solve).

 

To make it even better and more complete, is it also possible to check whether a tappuntnummer has already been used in the drawing?

So when the attributevalue 001 already occurs in one of the blocks, there will be a notification that it is no longer allowed to use this number. Maybe too much to ask but would be great.

 

 

I can unfortunately not program a code from scratch f. I can only analyze an existing code and adjust it a little bit.
I would like to learn more about lisp. Are there books or websites with exercises, etc.?
Otherwise, I will continue to bother you guys on this forum.

0 Likes
Message 24 of 32

pbejse
Mentor
Mentor

@djurk_haas wrote:

To make it even better and more complete, is it also possible to check whether a tappuntnummer has already been used in the drawing?

So when the attributevalue 001 already occurs in one of the blocks, there will be a notification that it is no longer allowed to use this number. Maybe too much to ask but would be great.


We can do it really.. How bad do you want it?

 


@djurk_haas wrote:

I would like to learn more about lisp. Are there books or websites with exercises, etc.?
Otherwise, I will continue to bother you guys on this forum.


No worries, we can do it here. again How bad do you want it? 

😀

Tesla.png

 

Wait a minute, is that among the selected objects or all of the same block on the drawing?

 

0 Likes
Message 25 of 32

roland.r71
Collaborator
Collaborator

@pbejse wrote:

Wait a minute, is that among the selected objects or all of the same block on the drawing?

 


That's what it sounds like (all blocks inside the drawing)

& in addition i wonder: Do tappunt & keerpunt share numbers? or could there be doubles?

(like keerpunt 001 & tappunt 001)

0 Likes
Message 26 of 32

pbejse
Mentor
Mentor

@roland.r71 wrote:

 

That's what it sounds like (all blocks inside the drawing)

& in addition i wonder: Do tappunt & keerpunt share numbers? or could there be doubles?

(like keerpunt 001 & tappunt 001)


Now that is  great question @roland.r71  Makes it even more fun.

😊

 

 

0 Likes
Message 27 of 32

Sea-Haven
Mentor
Mentor

If its 1 block not to bad can defun the ssget every session and find max number. Do only once per session, set a global value "Checked". Can keep updating default value as a global also.

0 Likes
Message 28 of 32

pbejse
Mentor
Mentor

 


@djurk_haas wrote:

I would like to learn more about lisp, are there books or websites with exercises, etc.?
Otherwise, I will continue to bother you guys on this forum.


6 things that could have happened after @djurk_haas  last post.

  • Learning to code and working it out on their own  | Good for the OP
  • We scared him-off and vowed to never come back | Bad.
  • The OP doesn't need the tweak and settled with eyeballing the existing numbers | "I can do this myself"
  • Or, just lose interest | "forged aboud id"
  • The OP came to their senses and will be posting and answer to all our query any second now | whopee!

... 

jeopardy.png

Message 29 of 32

djurk_haas
Advocate
Advocate

Sorry for the late response I thought I did reply but sometimes my browser gets stuck.

Anyway it is for all blocks inside the drawing and there could be doubles like keerpunt 001 & tappunt 001.

0 Likes
Message 30 of 32

pbejse
Mentor
Mentor

@djurk_haas wrote:

Sorry for the late response I thought I did reply but sometimes my browser gets stuck.

Anyway it is for all blocks inside the drawing and there could be doubles like keerpunt 001 & tappunt 001.


Think I have time to look into this now.

 

If there are 2 or more with the same number, should the program "bump" the values on the other existing attributes?

wil  the user will be given a choice which of the say 3 will keep the number and the other will will be given a value that is not used yet?

 

 

0 Likes
Message 31 of 32

djurk_haas
Advocate
Advocate

The check only has to take place when a new block is placed.
If you then enter a double number, a message that you must enter a different value is sufficient.
It would of course be useful to get an overview (popup) with the numbers already used before entering a new number, but that is more of a wish (but very useful)

0 Likes
Message 32 of 32

pbejse
Mentor
Mentor

@djurk_haas wrote:

It would of course be useful to get an overview (popup) with the numbers already used before entering a new number, 


 

Command: TP-CHANGE

Select objects: Specify opposite corner: 4 found

Select objects:
Existing values - (001 002 003 004 006);<----missing number "005"
NUMMER_TAPPUNT <007>: 5 ; <----user either enter 5 or press enter to accept next number

"N.v.t.: Tappunt onder/boven"
Existing values - (001 002 003 004 006)
NUMMER_KEERKLEP <007>: 5

Existing values - (001 002 003 004 005 006);<--- "005"  included on this prompt
NUMMER_TAPPUNT <007>;<-- User press Enter

 

HTH

 

0 Likes