Jump to content

To check if the correct block was selected by user


Recommended Posts

Posted (edited)

Hello, 

New to LISP here. 

 

I was writing a program and I need it to:

(1) identify old title blocks by name -> (2) Gather some attribute data and temporarily store it -> (3) purge the drawing -> (4) paste in new blocks -> (5) populate new title block attributes. 

 

got steps 2, 3, and 5 all good. 

 

For step 1, I'm using entsel to ask the user to select the block, but I need to make sure they select the correct one. I can use the name of the block as a check because it's unique. Can someone help me with the code for this?

 

(setq obj1 (car (entsel "\nSelect the title block:")))  -> this is what I use to ask the user to select the block and then use obj1 to get attributes. 

 

Thanks. 

 

 

Edited by G.Aquarius
Posted

just use ssget if your looking for a unique named block. then their isn't a need for the user to select anything.

 

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "block name") (410 . "Model"))))

 

I would also pull the base point of said block to help with step 4.

  • Like 2
Posted
5 hours ago, mhupp said:

just use ssget if your looking for a unique named block. then their isn't a need for the user to select anything.

 

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "block name") (410 . "Model"))))

 

I would also pull the base point of said block to help with step 4.

 

 

You've been on your holidays too long....add this so that the the OP can keep using entitiy from a selection set: (setq obj (ssname ss 0)), and modifying the cons 410 to a variable (to be set earlier in the LISP) MyLayout - assuming the OP is working in paperspace for a title block, rather than modelspace0? Though if they are in that screen as they run this can use ctab. Assuming only 1 occurrence of the title block you might not need the cons 410 part.

 

(setq obj (ssname (ssget "_X" (list (0 . "INSERT") (2 . "block name") (cons 410 MyLayout) ))) 0 ))

 

 

For obvious reasons (it is a Sunday here), this is untested - might be typing errors

 

  • Like 2
Posted

Thank You @Steven P and @mhupp

 

here's the code that works (made some changes, syntax errors really nothing major) :)

 

(setq obj (ssname (ssget "_X" (list '(0 . "INSERT") '(2 . "MARS_Petcare_US Title Block") )) 0) )

 

Works great!!

  • Like 2
Posted

If you do want current layout only add.

(cons 410 (getvar 'ctab))

 

  • Like 1
  • 1 year later...
Posted
On 3/19/2023 at 6:17 AM, Steven P said:

Assuming only 1 occurrence of the title block you might not need the cons 410 part.

Hello, reviving this thread as I'm working on an iteration of the code I worked on previously. 

 

I wanted to know if there are multiple blocks with the same name, and even same attribute into in them, how can I change them? 

 

In a broader sense, I'm trying to make a LISP that

-> identifies the section markers 

-> retrieve the attribute information, position and all the states of the dynamic blocks (I know how to save the attribute info, but need help with the other stuff)

-> deletes them and purges drawing (done)

-> bring in new block from a different drawing and input the attribute information previously saved. (I'll figure this out afterwards, but I'm planning to save all the block info as variables and using them later)

 

I've attached a sample of what I'm working with. 

Test For CADTutor.dwg

Posted

The simplest way is get all blocks say in layout then check what is their EffectiveName (RO) = "SECTION MARKER" if it matches your block name continue. 

 

A example

(setq obj (vlax-ename->vla-object (car (entsel "\nSelect a block "))))
(setq eff (vlax-get obj 'Effectivename))

 

 

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