Jump to content

Need help to complete block related lisp.


AbdRF

Recommended Posts

Hello,

I want to extract the handle value of a block (master block-single selection) and assigned that value to the last attribute tag found in the other multiple selected blocks irrespective of block and tag name.
The blocks will have at the most 3 attributes (I mean to say that if there is one tag ,assign handle value to first tag, if there are two tags,assign handle value to the second tag and so on)
Further I want to add that all the blocks in a given drawing will have same number of tags (either all of them will have 1 tag, 2 tags or 3 tags) and there will be no mix cases


So here is my trail in which I am able to extract the handle ID of the master block but I don't know how to assign this value to the last attribute tag of the selected child blocks ( block name and tag name will vary from case to case but handle value should be assigned to the last tag found in each block)

(defun c:AV  (/ a b hv)
    (setq a (entsel "\nSelect the Master Block: "))
    (setq b (entget (car a)))
    (setq hv (cdr (assoc 5 b)))

Here I am attaching the image for further clarity
image.thumb.png.5288ebe2919fe08500d36deecd670de1.png

Please help me to complete this lisp
I am attaching the sample drawing file.

Thanks!

Master-child block.dwg

Edited by AbdRF
Link to comment
Share on other sites

Have you had a look at Lee's Attribute Functions link? You can use those.

 

Or here's one without his reference (although it looks very similar in nature)

 

(defun c:blkhandler ( / adoc atts hand i mast ss tag vlent)
  (defun *error* (msg) (vla-EndUndoMark adoc) (princ (strcat "\nError: " msg)))
  
  (setq tag "ins_no"	; <--- Tag attribute in block
	adoc (vla-get-ActiveDocument (vlax-get-acad-object))
	)
  (vla-StartUndoMark adoc)
  (while
    (null
      (and
	(setq mast (car (entsel "\nSelect master block: ")))
	(eq (cdr (assoc 0 (entget mast))) "INSERT")
	)
      )
    (princ "\nInvalid selection")
    )

  (setq hand (cdr (assoc 5 (entget mast)))
	tag (strcase tag)
	)
  
  (if (setq ss (ssget '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (and
	(vlax-write-enabled-p (setq vlent (vlax-ename->vla-object (ssname ss (setq i (1- i))))))
	(setq atts (vlax-invoke vlent 'GetAttributes))
	(vl-some '(lambda (y) (if (eq (vla-get-TagString y) tag) (vla-put-TextString y hand))) atts)
	)
      )
    )
  (vla-EndUndoMark adoc)
  (princ)
  )

 

  • Thanks 1
Link to comment
Share on other sites

7 minutes ago, Jonathan Handojo said:

Have you had a look at Lee's Attribute Functions link? You can use those.

 

Or here's one without his reference (although it looks very similar in nature)

 


(defun c:blkhandler ( / adoc atts hand i mast ss tag vlent)
  (defun *error* (msg) (vla-EndUndoMark adoc) (princ (strcat "\nError: " msg)))
  
  (setq tag "ins_no"	; <--- Tag attribute in block
	adoc (vla-get-ActiveDocument (vlax-get-acad-object))
	)
  (vla-StartUndoMark adoc)
  (while
    (null
      (and
	(setq mast (car (entsel "\nSelect master block: ")))
	(eq (cdr (assoc 0 (entget mast))) "INSERT")
	)
      )
    (princ "\nInvalid selection")
    )

  (setq hand (cdr (assoc 5 (entget mast)))
	tag (strcase tag)
	)
  
  (if (setq ss (ssget '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (and
	(vlax-write-enabled-p (setq vlent (vlax-ename->vla-object (ssname ss (setq i (1- i))))))
	(setq atts (vlax-invoke vlent 'GetAttributes))
	(vl-some '(lambda (y) (if (eq (vla-get-TagString y) tag) (vla-put-TextString y hand))) atts)
	)
      )
    )
  (vla-EndUndoMark adoc)
  (princ)
  )

 


@Jonathan Handojo First of all ,thanks for looking into my issue and helping me out. I am just a beginner in lisp  ,so I am gradually learning.
Now I wanted to know how can we export the block handle value using lisp into csv . I have done some research and got to know that there is function called "vla-get-handle".
I got one lisp from Internet which export  block details such as  (block name, rotation, layer, Insertion Point) .Can you help me to add the two additional column - "handle" column and attribute tag "Ins_no" value column in the below attached lisp?

Thanks 
bdataexp.lsp

Link to comment
Share on other sites

Just now, Jonathan Handojo said:

For a beginner, that's quite a very nice code..

@Jonathan Handojo That is not written by me ,I got it on Internet while searching as I mention above 😅. I am not skillful enough to write such level code.

Link to comment
Share on other sites

2 minutes ago, Jonathan Handojo said:

Try looking into Write CSV, maybe you can get some ideas. If not, just yell out.


This is good stuff, I will surely look out .May be I will learn gradually 😀

Link to comment
Share on other sites

I notice the code appears to use tag's with attributes you can get the count of how many so can change any attribute without knowing its tag name. So for 2 3 4 its always the last attribute to be changed as per OP request can use foreach and a counter.  

Link to comment
Share on other sites

13 hours ago, Jonathan Handojo said:

Here you have it. I've modified it and left comments on where I've modified it.


@Jonathan Handojo I would like to point out one issue .The last column "Tag" should extract the attribute value associated with the tag "INS_NO" and not tag name. I hope you will amend this.Thanks for your effort
 
image.png.2ab29fdf02c3d5200165ee91ac540a1f.png

Link to comment
Share on other sites

13 hours ago, Jonathan Handojo said:

Oh, and be sure to check my Block Overkill program to remove any duplicates that may exist and give you incorrect results.


It looks so cool .I will surely check this out and give my feedback after testing it on my drawings.Thanks

Link to comment
Share on other sites

23 minutes ago, Jonathan Handojo said:

Wouldn't that just be the handle at column G above? I don't get it.

@Jonathan Handojo Basically I have to establish relationship between some blocks (master-child) using handle since it is persistent and unique.

For eg- say if I have 100 blocks in the drawing and have assigned master-child for 40 blocks.So the tag "Ins_No" should have value only for child blocks ,rest for all blocks (including master) it will be blank.So in csv, it will be clear that exactly which blocks are child and by looking at their attribute value ,it will tell about its master block!!

 

I hope it is clear to you

Link to comment
Share on other sites

On 4/18/2020 at 7:44 PM, Jonathan Handojo said:


@Jonathan Handojo this is so much complication which I don't want. I only need that "Tag" column in CSV to have attribute values rather than tagname and nothing else .This code should not ask anything about masterblock as it is already defined.

Thanks for your effort

Link to comment
Share on other sites

On 4/16/2020 at 11:35 PM, Jonathan Handojo said:

Here you have it. I've modified it and left comments on where I've modified it.

 

Oh, and be sure to check my Block Overkill program to remove any duplicates that may exist and give you incorrect results.

BDataExport.lsp 2.9 kB · 4 downloads


@Jonathan Handojo This one was almost suitable for my purpose.The only thing I wanted is that "Tag" column should extract the attribute value (associated with tag INS_NO) rather than tag name. I don;t want much complication. Just a small change 

I request you to also remove the option of "Other/None" , it should export just whatever attribute value is assigned to the tag "INS_NO" for every block.

Edited by AbdRF
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...