Select a point or object

Select a point or object

C.Utzinger
Collaborator Collaborator
1,196 Views
11 Replies
Message 1 of 12

Select a point or object

C.Utzinger
Collaborator
Collaborator

HI

 

I'm looking for a code where I can with one user Input get a Point OR an object.

 

What i want to do is when i just pink a Point then it will insert the block with attributes or when the block allready exists, select the this block and change the attributes.

 

Please help :).

 

Regards 

0 Likes
Accepted solutions (1)
1,197 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant

Use (nentselp) function.

 

(defun c:ReselectionWithPoint ()
  
  (if (and (setq pnt (getpoint "\nSelect the point"))
           (setq ent (nentselp pnt))
           )
    (cond ((= (length ent) 4)
           (setq ent (car (cadddr ent)))
           (sssetfirst nil (ssadd ent)))
          ((= (length ent) 2)
           (setq ent (car ent))
           (sssetfirst nil (ssadd ent))))
    (princ "\nNo entity under the point"))
  (princ)
  )
Message 3 of 12

C.Utzinger
Collaborator
Collaborator

HI

 

I have the code like below.

 

Is there a better way to Change the block attributes?

 

And i don´t understand all the things the command "_.attedit" asks me.

 

I send you the dwg with the block. I just want to select the block an Change with one user Input both letters or numbers.

 

Thank you.

 

 

 

 


(defun c:<Test7 ( / *error* BEingabe oATTREQ oATTDIA Attrib pnt ent lay cmd BEingabe) (defun *error* (errmsg) (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break")) (princ (strcat "\nError: " errmsg))) (setvar 'CLAYER lay) (setvar 'CMDECHO cmd) (setvar 'ATTREQ oATTREQ) (setvar 'ATTDIA oATTDIA) (princ)) (setq lay (getvar 'CLAYER) cmd (getvar 'CMDECHO)) (command "_.-LAYER" "_m" "-I-Schnittbezeichnung" "_co" "6" "-I-Schnittbezeichnung" "") (setq oATTREQ (getvar 'ATTREQ) oATTDIA (getvar 'ATTDIA)) (setvar 'ATTREQ 1) (setvar 'ATTDIA 0) (setq Attrib 1) (if (and (setq pnt (getpoint "\nEinfügepunkt oder Schnittbezeichnung wählen: ")) (setq ent (nentselp pnt)) ) (cond ((= (length ent) 4) (setq ent (car (cadddr ent))) (sssetfirst nil (ssadd ent))) ((= (length ent) 2) (setq ent (car ent)) (sssetfirst nil (ssadd ent)))) (progn (princ "\nKein Objekt gewählt! ") (setq Attrib 2) (command "_.-insert" "spi-schnitt" pnt "1" "1" "" (setq BEingabe (strcase (getstring "\nSchnittbezeichnung angeben: "))) BEingabe))) (if (= Attrib 1)(command "_.attedit" ?????????)) (setvar 'CLAYER lay) (setvar 'ATTREQ oATTREQ) (setvar 'ATTDIA oATTDIA) (prin1) ) ; end of defun
0 Likes
Message 4 of 12

C.Utzinger
Collaborator
Collaborator

This one works now for the last block i have insertet, but not for the last selection.

 

Please help...

 

 

 

(vl-load-com)
(defun c:<Test7 ( / *error* BEingabe oATTREQ oATTDIA Attrib pnt ent lay cmd BEingabe)
	
	(defun *error* (errmsg)
    	    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      		(princ (strcat "\nError: " errmsg)))
    		(setvar 'CLAYER lay)
    		(setvar 'CMDECHO cmd)
    		(setvar 'ATTREQ oATTREQ)
    		(setvar 'ATTDIA oATTDIA)
    		(princ))

	(defun LM:vl-setattributevalue ( blk tag val )
    		(setq tag (strcase tag))
    		(vl-some '(lambda ( att )
                (if (= tag (strcase (vla-get-tagstring att)))
                  (progn (vla-put-textstring att val) val)))
             	(vlax-invoke blk 'getattributes)))

	(setq lay (getvar 'CLAYER)
              cmd (getvar 'CMDECHO))
	
	(command "_.-LAYER" "_m" "-I-Schnittbezeichnung" "_co" "6" "-I-Schnittbezeichnung" "")

	(setq oATTREQ (getvar 'ATTREQ)
              oATTDIA (getvar 'ATTDIA))
  	(setvar 'ATTREQ 1)
  	(setvar 'ATTDIA 0)  	
		
	(setq Attrib 1)

  	(if (and (setq pnt (getpoint "\nEinfügepunkt oder Schnittbezeichnung wählen: "))
           	(setq ent (nentselp pnt))
           	)
    	  (cond ((= (length ent) 4)
           	(setq ent (car (cadddr ent)))
           	(sssetfirst nil (ssadd ent)))
          	((= (length ent) 2)
           	(setq ent (car ent))
               	(sssetfirst nil (ssadd ent))))
    	  (progn 
		(princ "\nKein Objekt gewählt! ")
  		(setq Attrib 2)
		(command "_.-insert" "spi-schnitt" pnt "1" "1" "" 
		   (setq BEingabe (strcase (getstring  "\nSchnittbezeichnung angeben: "))) 
			BEingabe)))
	
	(if (= Attrib 1)(progn  (setq en-blk1 (entlast))
				(setq BEingabe (strcase (getstring "\nNeue Schnittbezeichnung angeben: ")))
				(LM:vl-setattributevalue (vlax-ename->vla-object en-blk1) "rechts" BEingabe)
      				(LM:vl-setattributevalue (vlax-ename->vla-object en-blk1) "links" BEingabe)))	

	(setvar 'CLAYER lay)
	(setvar 'ATTREQ oATTREQ)
  	(setvar 'ATTDIA oATTDIA)
	(prin1)	
	
) ; end of defun
0 Likes
Message 5 of 12

C.Utzinger
Collaborator
Collaborator

 

I am so stupid, now it works!!!

 

Ok... Can I omit the variable "Attrib"???

 

And sometimes when I select the block (for example near the Attribute) it doesn´t work, because it don´t select the block. Can you fix this?

 

 Kind regards...

 

 

(vl-load-com)
(defun c:<Test7 ( / *error* BEingabe oATTREQ oATTDIA Attrib pnt ent lay cmd BEingabe)
	
	(defun *error* (errmsg)
    	    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      		(princ (strcat "\nError: " errmsg)))
    		(setvar 'CLAYER lay)
    		(setvar 'CMDECHO cmd)
    		(setvar 'ATTREQ oATTREQ)
    		(setvar 'ATTDIA oATTDIA)
    		(princ))

	(defun LM:vl-setattributevalue ( blk tag val )
    		(setq tag (strcase tag))
    		(vl-some '(lambda ( att )
                (if (= tag (strcase (vla-get-tagstring att)))
                  (progn (vla-put-textstring att val) val)))
             	(vlax-invoke blk 'getattributes)))

	(setq lay (getvar 'CLAYER)
              cmd (getvar 'CMDECHO))
	
	(command "_.-LAYER" "_m" "-I-Schnittbezeichnung" "_co" "6" "-I-Schnittbezeichnung" "")

	(setq oATTREQ (getvar 'ATTREQ)
              oATTDIA (getvar 'ATTDIA))
  	(setvar 'ATTREQ 1)
  	(setvar 'ATTDIA 0)  	
		
	(setq Attrib 1)

  	(if (and (setq pnt (getpoint "\nEinfügepunkt oder Schnittbezeichnung wählen: "))
           	(setq ent (nentselp pnt))
           	)
    	  (cond ((= (length ent) 4)
           	(setq ent (car (cadddr ent)))
           	(sssetfirst nil (ssadd ent)))
          	((= (length ent) 2)
           	(setq ent (car ent))
               	(sssetfirst nil (ssadd ent))))
    	  (progn 
		(princ "\nKein Objekt gewählt! ")
  		(setq Attrib 2)
		(command "_.-insert" "spi-schnitt" pnt "1" "1" "" 
		   (setq BEingabe (strcase (getstring  "\nSchnittbezeichnung angeben: "))) 
			BEingabe)))
	
	(if (= Attrib 1)(progn  (setq en-blk1 ent)
				(setq BEingabe (strcase (getstring "\nNeue Schnittbezeichnung angeben: ")))
				(LM:vl-setattributevalue (vlax-ename->vla-object en-blk1) "rechts" BEingabe)
      				(LM:vl-setattributevalue (vlax-ename->vla-object en-blk1) "links" BEingabe)))	

	(setvar 'CLAYER lay)
	(setvar 'ATTREQ oATTREQ)
  	(setvar 'ATTDIA oATTDIA)
	(prin1)	
	
) ; end of defun
Message 6 of 12

ВeekeeCZ
Consultant
Consultant
Accepted solution

I've rewritten it. This way it's more nature, I think.

 

(vl-load-com)
(defun c:<Test7 ( / *error* BEingabe oATTREQ oATTDIA Attrib pnt ent lay cmd BEingabe)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'CLAYER lay)
    (setvar 'CMDECHO cmd)
    (setvar 'ATTREQ oATTREQ)
    (setvar 'ATTDIA oATTDIA)
    (princ))
  
  (defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some '(lambda ( att )
                (if (= tag (strcase (vla-get-tagstring att)))
                  (progn (vla-put-textstring att val) val)))
             (vlax-invoke blk 'getattributes)))
  
  (setq lay (getvar 'CLAYER)
        cmd (getvar 'CMDECHO))
  
  (command "_.-LAYER" "_m" "-I-Schnittbezeichnung" "_co" "6" "-I-Schnittbezeichnung" "")
  
  (setq oATTREQ (getvar 'ATTREQ)
        oATTDIA (getvar 'ATTDIA))
  (setvar 'ATTREQ 1)
  (setvar 'ATTDIA 0)
  (setvar 'CMDECHO 0)
  

  (if (setq ent (car (entsel "\nEinfügepunkt oder Schnittbezeichnung wählen <insert new>: ")))
    (progn
      (setq BEingabe (strcase (getstring "\nNeue Schnittbezeichnung angeben: ")))
      (LM:vl-setattributevalue (vlax-ename->vla-object ent) "rechts" BEingabe)
      (LM:vl-setattributevalue (vlax-ename->vla-object ent) "links" BEingabe))
    (progn
      (princ "\nSpeciefy point for block: ")
      (command "_.-insert" "spi-schnitt" pause "1" "1" ""
               (setq BEingabe (strcase (getstring  "\nSchnittbezeichnung angeben: ")))
               BEingabe)))
    
  (setvar 'CLAYER lay)
  (setvar 'ATTREQ oATTREQ)
  (setvar 'ATTDIA oATTDIA)
  (setvar 'CMDECHO cmd)
  (prin1)
  
  ) ; end of defun
0 Likes
Message 7 of 12

C.Utzinger
Collaborator
Collaborator

OHH!!!

 

Thank you that's great!!!

 

 

Kind regards.

 

Christian

0 Likes
Message 8 of 12

john.uhden
Mentor
Mentor

My ancestors came from Essen, but I have no idea what Schnitselberg is, except maybe a frankfurter.  Luckily BeeKeeCZ is multilingual.

John F. Uhden

0 Likes
Message 9 of 12

C.Utzinger
Collaborator
Collaborator

LOL XD XD XD

0 Likes
Message 10 of 12

ВeekeeCZ
Consultant
Consultant
I can order a Schnitzel mit Pommes if we are in Austria but nothing more. I can understand the basics from my school years, but that's not really enough. My parents thought that would be a good idea speak as our 2 neighbors does and Germany is our biggest business partner.. but it was wasted time.. Even with a German is better to speak in his second language.. then we are even. Fortunately nowadays there is the Google translator so I can understand a German, Portuguese, Russian, even a Chinese.. 😉
0 Likes
Message 11 of 12

C.Utzinger
Collaborator
Collaborator

LLLLOOOOOLLLL

0 Likes
Message 12 of 12

john.uhden
Mentor
Mentor

@C.Utzinger wrote: "LOL XD XD XD"

 

Ahah.  I am no dumbkopf.  I CAN understand German!  You are cursing at me, right?

John F. Uhden

0 Likes