Select block, not attribute

Select block, not attribute

C.Utzinger
Collaborator Collaborator
909 Views
5 Replies
Message 1 of 6

Select block, not attribute

C.Utzinger
Collaborator
Collaborator

HI

 

I have a little problem with the functions: ut:titel and ut:Kopie

 

For making them work correctly i need to select the attribute. I don't know how to make them work selecting just the block.

 

Please a little help...

 

 

(vl-load-com)
(defun c:<Schnitt ( / *error* nVAR oVAR ent ensel BEingabe skala adoc fail)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (mapcar 'setvar nVAR oVAR)
    (if fail (alert "Schnittbezeichnungen mit verschiedenen Inhalten \n(z.B. A & 1) können nicht neu geordnet werden!"))
    (vla-endundomark adoc)
    (princ))

  (defun ut:titel ( enti / att fieldcode titel pnt)
    (setq att (nentselp (cadr enti))
          att (vlax-ename->vla-object (car att)))
    (setq fieldcode (strcat "%<\\AcObjProp Object\(%<\\_ObjId " (itoa (vla-get-objectid att)) ">%\).TextString>%")
          titel (strcat "Schnitt " fieldcode "-" fieldcode "  1:" (itoa *mstb*))) 
    (command "_.insert" "SPI-schnitt_Text" "_s" skala "_r" 0)
    (while (> (getvar "cmdactive") 0)(command (setq pnt (getpoint "Einfügepunkt wählen:")) titel))

    (command "_.insert" "SPI-Schnitttiteltext" pnt skala "")
    (command "_explode" "_l")
    (command "_purge" "_bl" "SPI-Schnitttiteltext" "_n")

    (princ (strcat "\nSchnittabhängiger Titel erstellt."))
  )

  (defun ut:kopie ( enti / att fieldcode titel)
    (setq att (nentselp (cadr enti))
          att (vlax-ename->vla-object (car att)))
    (setq fieldcode (strcat "%<\\AcObjProp Object\(%<\\_ObjId " (itoa (vla-get-objectid att)) ">%\).TextString>%")) 
    (command "_.-insert" "spi-schnitt-k" pause skala skala pause fieldcode fieldcode)
  )

  (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)))
  
  (or *mstb* (setq *mstb* 50))
  (or *einhsk* (setq *einhsk* 1))
  (setq skala (* (/ *mstb* 50.0) *einhsk*)) 

  (if (not (tblsearch "block" "SPI-Schnittbezeichnungen")) 
        (progn 
          (command "_.insert" "SPI-Schnittbezeichnungen")
          (command)))

  (vla-endundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
  (vla-startundomark adoc)

  (setq oVAR (mapcar 'getvar (setq nVAR '(CLAYER ATTREQ ATTDIA CMDECHO))))
  (setvar 'ATTREQ 1)
  (setvar 'ATTDIA 0)
  (setvar 'CMDECHO 0)
  
  (if (tblsearch "LAYER" "-I-Schnittbezeichnung")
      (progn
        (setvar "CLAYER" "-I-Schnittbezeichnung")
        (command "_.-LAYER" "_on" "-I-Schnittbezeichnung" "")
      ) 
      (command "_.-LAYER" "_m" "-I-Schnittbezeichnung" "_co" "6" "-I-Schnittbezeichnung" ""))

  (while (progn
         (setvar 'ERRNO 0)		;; reset errno
         (setq ensel (entsel "\nSchnittbezeichnung wählen oder <Neue einfügen>: "))
         (cond ((= 7 (getvar 'ERRNO)) nil)	;; http://help.autodesk.com/view/ACD/2018/ENU/?guid=GUID-97327347-2A13-4CBC-BDBF-979C7F1CABD5
               ((not ensel) nil)   
               ((not (wcmatch (cdr (assoc 0 (entget (car ensel)))) "INSERT"))
                (princ "\nKeine Schnittbezeichnung gewählt!"))
               ((not (wcmatch (strcase (vla-get-effectivename (vlax-ename->vla-object (car ensel)))) "SPI-SCHNITT,SPI-SCHNITT-VERSETZT,SPI-SCHNITT-WINKEL"))
                (princ "\nKeine Schnittbezeichnung gewählt!"))
               (T nil))))
  (if ensel
    (progn
      (setq BEingabe (strcase (getstring "\nNeue Schnittbezeichnung angeben oder [TItel/KOpie/NEuordnen]: "))
            ent (car ensel))
      (cond ((= BEingabe "TI")(ut:titel ensel))
            ((= BEingabe "TITEL")(ut:titel ensel))
            ((= BEingabe "KO")(ut:kopie ensel))
            ((= BEingabe "KOPIE")(ut:kopie ensel))
            ((= BEingabe "NE")(ut:ordnen))
            ((= BEingabe "NEUORDNEN")(ut:ordnen))
            (T (LM:vl-setattributevalue (vlax-ename->vla-object ent) "rechts" BEingabe)
               (LM:vl-setattributevalue (vlax-ename->vla-object ent) "links" BEingabe)
               (princ (strcat "\nSchnittbezeichnung auf " BEingabe "-" BEingabe " geändert.")))
      )
    )
    (progn
      (princ "\nEinfügepunkt angeben: ")
      (command "_.-insert" "spi-schnitt" pause skala skala pause
               (setq BEingabe (strcase (getstring  "\nSchnittbezeichnung angeben: ")))
               BEingabe)
      (princ (strcat "\nSchnittbezeichnung " BEingabe "-" BEingabe " eingefügt."))
    )
  )
  (command "_.regen")    
  (*error* "end")
  (prin1)
) ; end of defun
0 Likes
Accepted solutions (1)
910 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
nentselp gets the object within a block. Try entsel instead.
0 Likes
Message 3 of 6

ВeekeeCZ
Consultant
Consultant

I would say that you would know how entsel, nentsel or nentselp works. Do you?

Your wording is not clear, where you need what to select... why is that wrong...

 

And ALWAYS post a test file. It's much faster to us to see the isues while running the program than reading the code. 

Message 4 of 6

C.Utzinger
Collaborator
Collaborator

HI

 

You're wright, i have my difficulties understanding this.

I would be glad if you help me to understand this.

 

I have attached a sample file.

 

Thank you very much...

0 Likes
Message 5 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, now I understand. You have issue when an user picks a block by other entity then attribute. So in this case you need get the attribute ename by tag, right - the tag name is always knows or predictable. So rewrite your code - the main selection keep using (entsel), but to get att ename use att's TAG instead of current (nentselp).

 

So here you have your function using autolisp.

 

(defun :GetAttibByName (blk tag / ent)

  (while (= "ATTRIB" (cdr (assoc 0 (setq ed (entget (setq blk (entnext blk)))))))
    (if (= (strcase (cdr (assoc 2 ed))) tag)
      (setq ent blk)))
  ent
)


(defun c:Test ()
  (setq blk (car (entsel)))
  (:GetAttibByName blk "RECHTS"))

The definition of block in the database looks like this: ename-of-block -> ename-of-attrib1 -> ename-of-attrib1 -> ename-of-seqend. SEQEND in always the last, so you can make your loop while is ATTRIB or until is SEQEND. You can try the second way by yourself.

 

Some other methods you can learn from HERE

 

Message 6 of 6

C.Utzinger
Collaborator
Collaborator

Thank you BeeKeeCZ

 

Now I could make it work.

 

 

Kind regards

0 Likes