Jump to content

Recommended Posts

Posted

hello:

 

(SETQ LEnt (ENTGET (SSNAME (SSGET "x" (list (cons 2 "BLOCK1")) ) 0)))

 

this line extracts the list of an entity called  "BLOCK1"

 

but in some drawings that I manage can I have entity called  "BLOCK1" or "BLOCK2"

 

I want to use that line to use it with the two names of the entities.

 

 

maybe using the function "OR"

 

 

HELP PLEASE 

 

Posted (edited)

This is pulling entget data from the first item in the selection set. What I mean is the entity will be random because their is a change for both the blocks to be first. That seem like it might cause more errors depending on what your lisp is doing.

 

This will always be BLOCK1 entget data

(setq LEnt (entget (tblobjname "BLOCK" "BLOCK1")))
Edited by mhupp
  • Like 1
Posted

It depends on what data the OP is looking to obtain from the entity, i.e. whether the data pertains to the block reference or the block definition; the suggestion from @mhupp is obtaining data from the block definition, whereas the code from the OP is obtaining data from the block reference.

  • Like 1
  • Agree 1
Posted

I use these two types of files...

 

 

within ABS-457860-001  there's a block reference named BLOCK1

within ABS-457875-001  there's a block reference named BLOCK2

 

 

I need the following:

1.- from the name of the file the code is taken  457860-001 (if it has another name it will be another code)  

and join with "PRE-" in block reference.

 

2.- from the name of the file the code is taken  457860 (if it has another name it will be another code)  

and join with "SUB-" in block reference.

 

be either name BLOCK1 or BLOCK2

the result inside the file would be like in the image...

 

image.thumb.png.65d3008866939a89c06787203585eec2.png

ABS-457860-001.dwg ABS-457875-001.dwg

Posted

Maybe something like this

 

(defun c:test ( / ss obj blk att1 atts dwgname)
(setq ss (ssget "x" '((0 . "INSERT")(cons 2 "Block1,Block2")(410 . "Model"))))

(if (= ss nil)
  (alert "no matching blocks")
  (progn 
  (setq blk (ssname ss 0))
  (setq obj (vlax-ename->vla-object (ssname ss 0)))
  (setq atts (vlax-invoke obj 'Getattributes))
  (setq dwgname (strcat "Pre-" (getvar 'dwgname)))
  (setq att1 (nth 0 atts))
  (vla-put-textstring att1 dwgname)
  )
)
(princ)
)

 

Posted
56 minutes ago, BIGAL said:

Maybe something like this

 

(defun c:test ( / ss obj blk att1 atts dwgname)
(setq ss (ssget "x" '((0 . "INSERT")(cons 2 "Block1,Block2")(410 . "Model"))))

(if (= ss nil)
  (alert "no matching blocks")
  (progn 
  (setq blk (ssname ss 0))
  (setq obj (vlax-ename->vla-object (ssname ss 0)))
  (setq atts (vlax-invoke obj 'Getattributes))
  (setq dwgname (strcat "Pre-" (getvar 'dwgname)))
  (setq att1 (nth 0 atts))
  (vla-put-textstring att1 dwgname)
  )
)
(princ)
)

 

Just a nitpicky thing but you only need to check if 'ss' exists not if it's equal to nothing. Swap the logic.

 

(if ss
    (progn (setq blk (ssname ss 0))
	   (setq obj (vlax-ename->vla-object (ssname ss 0)))
	   (setq atts (vlax-invoke obj 'getattributes))
	   (setq dwgname (strcat "Pre-" (getvar 'dwgname)))
	   (setq att1 (nth 0 atts))
	   (vla-put-textstring att1 dwgname)
    )
    (alert "no matching blocks")
  )

and if there are attributes might as well use the '(66 .1) code to the filter.

 

 

Posted

THANK YOU ALREADY GAVE ME THE SOLUTION :)

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...