Insert block and select attribute with field

Insert block and select attribute with field

will.wydock
Advocate Advocate
2,038 Views
9 Replies
Message 1 of 10

Insert block and select attribute with field

will.wydock
Advocate
Advocate

Hi,

 

My company has decided to have the standard keynotes in our drawings match the national cad standards. Our previous standard had  a us insert a block that would be exploded and within that would be 2 block(keynote and note blocks) with fields linking the numbers. I have been tasked with automating a way to insert a block and then select an attribute from another block to create a field inside the inserted block. Below is a lisp routine within our library that would allow us to select 2 text/attributes and link the values. I think this is where I should be starting but I don't really know lisp very well and am not sure where to start. I attached an example of what they would like to do.

 

Any help is greatly appreciated.

 

(defun c:gcs-MakeField (/ enam elst objid fldexp enm2)
	(vl-load-com)
	(while (null (setq enam (car (nentsel "\nSelect TEXT/MTEXT/ATTRIBUTE: "))))
		(princ "Nothing Selected")
	)
(cond ((and
			(setq elst (entget enam))
		  (setq elst (member  (cdr (assoc 0 elst)) '("ATTRIB" "TEXT" "MTEXT")))
			(setq objid (vla-get-ObjectId (vlax-ename->vla-object enam)))
			(setq fldexp (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa objid) ">%).TextString>%"))
			(setvar "cmdecho" 0)
			(progn (If (and (not (= glay ""))
		      		   	   (member glay (mapcar 'strcase (cons "MODEL" (layoutlist)))))
											(setvar 'Ctab glay)) T)
			(setq enm2 (car (nentsel "\nSelect String: ")))
		  (setq enam (member  (cdr (assoc 0 (entget enm2))) '("ATTRIB" "TEXT" "MTEXT")))
		  (not (vla-put-textstring (vlax-ename->vla-object enm2) fldexp))
		  (setvar "cmdecho" 1)
		  (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
			  )
       )
      )
      (vl-some
         '(lambda (j) (if (null (eval (car j))) (princ (cadr j))
              )) 
         '((elst "\nSelected Entity is Not valid for Field value.")
           (enm2 "\nNothing Selected")
           (enam "\nSelected Entity is Not valid for Field value."))
         )
	(princ)
)
0 Likes
Accepted solutions (1)
2,039 Views
9 Replies
Replies (9)
Message 2 of 10

pbejse
Mentor
Mentor

This sounds interesting. 

 


@will.wydock wrote:

... I have been tasked with automating a way to insert a block...


Best if you would do this  from Tool Palettes <Ctr;+3>

 


@will.wydock wrote:

 

. I have been tasked with automating a way to insert a block and then select an attribute from another block to create a field inside the inserted block.

 

From the attached sample drawing, which one is the source?  assuming its "gcs-Note-Keyed"  and the target is 

"gcs-Tag-Hexagon" Do you want both values from the key notes to appear on the tag?

 

 

0 Likes
Message 3 of 10

will.wydock
Advocate
Advocate

We currently have them on tool pallette, Because we are using both Revit and CAD in our office so we are moving toward the NCS. We had to get away from the previously used inserted block, which was 2 blocks with the attributes linked inside another block that was exploded upon insertion.

 

Yes, gcs-Note-Keyed is the source with potential for multiple Hexagon Tags linked to it.

0 Likes
Message 4 of 10

pbejse
Mentor
Mentor

On your example , only "2" but not "ANOTHERE EXAMPLE KEYNOTE".  You only need the NUMBER and not the the LINE# correct?

 

 

 

0 Likes
Message 5 of 10

will.wydock
Advocate
Advocate

Yes, I only need the NUMBER

0 Likes
Message 6 of 10

pbejse
Mentor
Mentor

@will.wydock wrote:

Yes, I only need the NUMBER


I think I have a pretty good idea how to go about automating this.

 

Q: Are the KEYED NOTES value  always the same?  meaning KEY NOTES 1 will always be "ABCDE" on any project?  or it varies per project? The former makes more sense on why you are using tool palette, otherwise the block source will be diffrent per package.

 

Insert the KEYED NOTES from Tool palette, explode [ or mayber not ] then select one or more  tags to assign the value. so thats basically it? 

 

 

 

 

 

 

0 Likes
Message 7 of 10

will.wydock
Advocate
Advocate

The keynote values are different per cad file, to give you an idea of how we are currently doing our keynotes i have attached the basic blocks. Just explode gcs-Note-KeyedwithHex to see our current setup when the block is exploded. This would represent a single note.

 

I was thinking it would be select the value for the tag, then insert the block with the field

0 Likes
Message 8 of 10

pbejse
Mentor
Mentor

@will.wydock wrote:

The keynote values are different per cad file


Got that.

If you are inserting the unexploded keynotes  from a tool palette, and it differs for every project? or per detail sheet?, where do you store it? I just need to understand your process.

 


@will.wydock wrote

I was thinking it would be select the value for the tag, then insert the block with the field


Doing it manually:

  • Insert the "gcs-Note-KeyedwithHex"  [ tool palette ]
  • Place it under the KEYED NOTES header
  • explode the inserted block
    • Once exploded , that is the only time you assign a value to it? or the value is already there?
  •  select the number value from the exploded block ( named "gcs-Tag-Hexagon")

 

  • select the target or  Insert the target block taking the string from the source as field value.
    • Odd thing though, the target block the same name as the exploded source  "gcs-Tag-Hexagon" ( but different somehow | from the first attachment) 

Wish we can get a look at a populated sheet to get a better understanding. 

 

 

0 Likes
Message 9 of 10

will.wydock
Advocate
Advocate

I have attached an example

0 Likes
Message 10 of 10

pbejse
Mentor
Mentor
Accepted solution

You have not replied to this.

Once exploded , that is the only time you assign a value to it? or the value is already there?

 

I skipped the insert and explode partand  let's  start with the Keyed Notes are already populated similar to your attached sample drawing

 

;;;		 	Not What I Had In Mind But..			;;;
;;;			pBe | Sep 2019					;;;
;;;			- gcs-MakeField	< -- this guy 			;;;

(defun c:NWIHIMB ( / 	gcs-MakeField_v source _AttFunc spc bname source
		  	data fieldvalue sp p insertedblock) 		
  
(defun gcs-MakeField_v (enam / objid fldexp)
  (setq objid (vla-get-ObjectId enam))
  (setq	fldexp (strcat "%<\\AcObjProp Object(%<\\_ObjId "
		       (itoa objid)
		       ">%).TextString>%"
	       )
  )
)

(defun _AttFunc (en lst / vals v)
  (mapcar (function
	    (lambda (at)
	      (setq
		vals (list (vla-get-tagstring at) (vla-get-textstring at) at)
	      )
	      (if (and lst (setq v (assoc (car vals) lst)))
		(vla-put-textstring at (cdr v))
	      )
	      vals
	    )
	  )
	  (vlax-invoke
	    (if	(eq (type en) 'VLA-OBJECT)
	      en
	      (vlax-ename->vla-object en)
	    )
	    'Getattributes
	  	)
  	)
)
(setq spc
       (vlax-get (vla-get-ActiveLayout
		   (setq adoc (vla-get-activedocument (vlax-get-acad-object))
		   )
		 )
		 'Block
       )
)

		 
  (if
    (and
      (setq bname  (cdr (Assoc 2 (tblsearch "BLOCK" "gcs-Tag-Hexagon"))))
      (setq source (ssget "_+.:S:E" '((0 . "INSERT")(66 . 1)(2 . "gcs-Note-Keyed"))))
      (setq data (_AttFunc (ssname source 0) nil))
      (setq f (assoc "NUMBER" data))
      (setq fieldvalue (gcs-MakeField_v (last f)))
      (setq sp (vlax-get (last f) 'TextAlignmentPoint))
      )
	  (while
                (setq p (getpoint sp "\nTag Location :"))
                             (setq insertedblock (vlax-invoke spc 'InsertBlock p bname 1 1 1 0))
	    	             (_AttFunc insertedblock (list (cons "NOTE_NUM" fieldvalue)))
	    		     (vla-regen adoc acActiveViewport)
                             )
    	)
	    (vl-some
	    '(lambda (j)
	       (if (null (eval (car j)))
		 (princ (cadr j))
	       )
	     )
	    '((bname  "\nBlock \"GCS-TAG-HEXAGON\" Not found")
	      (source "\nInvalid or Null Selection")
	     )
	  )                 
  (princ)  
   )

 

 

 

0 Likes