Merging functions from 2 LISPs

Merging functions from 2 LISPs

Blue_Mojito
Advocate Advocate
2,407 Views
12 Replies
Message 1 of 13

Merging functions from 2 LISPs

Blue_Mojito
Advocate
Advocate

So, I found (in this forum from 2015 ) a nice working lisp that edits block attributes in sequence with prefix and suffix, etc. See attached "attribute_sequential_increment_NEW.lsp". However, the lisp updates the first attribute tag it finds, so is it possible to incorporate the "get attribute function.lsp" code into it to make it work on custom blocks. See attached "Get attribute list code".  I thought it would be as easy as copying the attribute code into the sequence lisp, but it did't do anything on my end. So I don't know if Im doing something wrong here or what needs to be updated.

 

Thanks in advance.

 

0 Likes
Accepted solutions (2)
2,408 Views
12 Replies
Replies (12)
Message 2 of 13

paullimapa
Mentor
Mentor

Try this modified AttInc.lsp that incorporates the GetTags & PickTag functions.

Limitations/Requirements:

1. Currently code does not support dynamic Blocks with Attributes

2. Need to first select a Block with Attributes to retrieve Tag name

3. Only Blocks with matching names are supported in the subsequent selections

FYI: Missing from your original posted code is function: INDEX_ADD which may run under function: SORT_FUN


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 13

Sea-Haven
Mentor
Mentor

If you use Nentsel rather than entsel, you can pick an attribute in a block it returns the properties of the attribute, so  Tagname is an obvious one. In a second pass you can get block name of actual block so you could then do an update of the blocks by name and Attribute tag name. 

 

If you could post a dwg with before and after,  show before blocks copy them and edit for show after. 

 

(setq att (entget (car (nentsel "\nPick an attribute "))))

((-1 . <Entity name: 8c27e060>) (0 . "ATTRIB") (5 . "D999") (330 . <Entity name: 8c27d620>) (100 . "AcDbEntity") (67 . 1) (410 . "D01") (8 . "DRGTEXT") (62 . 5) (100 . "AcDbText") (10 693.8875 56.125 0.0) (40 . 7.0) (1 . "PRELIMINARY DRAWING") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 4) (11 742.1875 59.625 0.0) (210 0.0 0.0 1.0) (100 . "AcDbAttribute") (2 . "DRAWING_STATUS") (70 . 0) (73 . 0) (74 . 0) (280 . 0))

"DRAWING_STATUS" is tag name.

0 Likes
Message 4 of 13

Blue_Mojito
Advocate
Advocate

This works great, but apparently it gets the name of the blocks as in *U2 and so on, so when I then go on to select the rest of the block to apply the sequence to, it says it didn't find any blocks with the name *U2 I've attached the file in which I tried it. This is the sequence of commands:

 

Command: ATTINCR

ENTER PREFIX (Ex: A...; if none, press Enter)

ENTER SUFFIX (Ex: ...Z; if none, press Enter)

ENTER STARTING NUMBER OF THE SEQUENCE (ANY INTEGER)1

Select Block Attribute Template to Retrieve Tag Name...
Select objects:

Select One [ITEM/SHEET/DWG.REF/ITEMNAME/*ITEMNAME/MAT'L/PART#/C/F/PR]: ITEM

Select Blocks Matching Name: *U2 To Change Tag: ITEM...
Select objects: Specify opposite corner: 0 found

Select objects:

No Blocks Selected Matching Name: *U2

0 Likes
Message 5 of 13

paullimapa
Mentor
Mentor
Accepted solution

The *U# in the Block name means it's a dynamic block which my original revisions did not accommodate (one of the limitations I posted). Try this updated AttInc.lsp version.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 13

Blue_Mojito
Advocate
Advocate
Thanks, no it works as intended. Thanks man!
0 Likes
Message 7 of 13

paullimapa
Mentor
Mentor

glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 13

Blue_Mojito
Advocate
Advocate
Actually, would it be possible to make the LISP not start the sequence with the last block copied? I don't know if I can just remove the (REVERSE LIST 1) function and make the sequence follow the actual order in which the blocks were copied.
0 Likes
Message 9 of 13

paullimapa
Mentor
Mentor

Go ahead and see what happens when you remove that. If that still doesn’t work then we may have to include more code to sort by insertion from either left to right or right to left. You let me know 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 13

Blue_Mojito
Advocate
Advocate

Yeah, I don't think removing it changes it. I get this error: 

 

; error: bad argument type: listp 11

 

I'm assuming 11 has to do something with the 11 blocks selected. I don't know if I'd want to go from L to R. I like that it orders the sequence in the order that they were copied (but backwards, unfortunately). The thing is I have a weird floor plan in which I'm trying to tag about 250 trellises, so not all are from L to R, that's why I liked that it renamed the sequence in order of being copied.

0 Likes
Message 11 of 13

paullimapa
Mentor
Mentor
Accepted solution

I actually don't mean to remove the entire line but just the reverse part.

So the last line before the final parenthesis:

; FORM_SSSET 
(DEFUN FORM_SSSET (SSSET BLOCKNAME / I TEMP_ELE LIST1)
  (SETQ I 0)
  (SETQ TEMP_ELE NIL)
  (SETQ LIST1 NIL_)
  (WHILE (< I (SSLENGTH SSSET))
    (SETQ TEMP_ELE (SSNAME SSSET I))
    (if (eq (strcase BLOCKNAME) (strcase (vla-get-effectivename (vlax-ename->vla-object TEMP_ELE)))) ; chk if blockname matches
     (SETQ LIST1 (CONS TEMP_ELE LIST1))
    )
    (SETQ I (+ I 1))
  )
 (REVERSE LIST1) ; line of code in question
)

 

Should now look like this line:

; FORM_SSSET 
(DEFUN FORM_SSSET (SSSET BLOCKNAME / I TEMP_ELE LIST1)
  (SETQ I 0)
  (SETQ TEMP_ELE NIL)
  (SETQ LIST1 NIL_)
  (WHILE (< I (SSLENGTH SSSET))
    (SETQ TEMP_ELE (SSNAME SSSET I))
    (if (eq (strcase BLOCKNAME) (strcase (vla-get-effectivename (vlax-ename->vla-object TEMP_ELE)))) ; chk if blockname matches
     (SETQ LIST1 (CONS TEMP_ELE LIST1))
    )
    (SETQ I (+ I 1))
  )
  LIST1
)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 13

Blue_Mojito
Advocate
Advocate

Yup, that did it. Sorry I'm not very savvy with LISPs. Thanks again.

0 Likes
Message 13 of 13

paullimapa
Mentor
Mentor

You are welcome… cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes