Jump to content

check if exist object or shape ?


insane

Recommended Posts

In example i have object named "picket" and i wanna check if there are these pickets then need put in to a list with an entity name. How to do this using vlax-ldata-put. Put these data in to database?

All working function would look like this.. I type command (all_data) in command input and the required data savings in autocad memory, and in the console i can check with command vlax-ldata-list

 

(defun c:tinklolinija (/ test pradzios_taskas)
 (vl-load-com)
(while
(if (tblsearch "block" "Piketas")

(princ "\nBlock Piketas not found.")
)
)
 (princ)

)

piketas.jpg

Edited by insane
Link to comment
Share on other sites

Look up how to use SSGET and filters you can search for blocks named picket.

(setq ss (ssget "X" (list (cons 0 "Insert")(cons 2 "Picket"))))

Edited by BIGAL
Link to comment
Share on other sites

I written code that print counted object names in alertbox but it doesnt show entity name.. What i am missing ?

(defun c:bcount ( / p1 b a n obj name)

(setq p1 (getstring "\Name of Block : "))
;get the name of the block

(setq b (cons 2 p1))
;construct a dotted pair - code 2 is for blocks

(setq a (ssget "x" (list b)))
;filter for the block name
     (progn
    )
(if (/= a nil)
;check if there are any blocks of that name

   (progn
   ;if there is…

	(setq n (sslength a))
    (setq ent (entlast a))
	;count the number of blocks

	(alert (strcat "\nThere are " (itoa n)  " in the DataBase. Enity: " (itoa ent) ))

    
	;display the result

   );progn
   ;if there are no blocks

	(alert "\nThere are none in the DataBase")
	;inform the user

);if

  (princ)

)

Link to comment
Share on other sites

in this case The name of block but not one all i need, but now its complicated.. Hmm i need another way how to get block names entity. Is there way to check if exact name of block exists ant ten put ta entity name in to database using vlax-ldata-put ?

Link to comment
Share on other sites

This sample will show you the entity-name and the vla-object-name of a selected object:

(vl-load-com)
(setq entity
      (car
    (entsel "\nSelect Item: ")    ; select item
      )
)
(if entity                ; check if something selected
 (progn                ; if so, do some stuff
   (princ (strcat "\nEntity is a: "    ; combine some strings
          (vl-princ-to-string (type entity))
                   ; convert type-output to string
      )
   )
   (princ (strcat "\nThe entity name is: "
          (vl-princ-to-string entity)
      )
   )

 )
)
(princ "\nAnd now VLA-data:")
(setq a-vla-object
      (vlax-ename->vla-object entity)    ; convert a ename to a vla-object
)
(princ
 (strcat "\nVLA-Entity: " (vl-princ-to-string a-vla-object))
)

Link to comment
Share on other sites

Thats ok i see it get entity name, but for me still need those entity names counting and write in to the database. Without using entsel function i mean automaticaly..when you press function in comman line

Link to comment
Share on other sites

Thats ok i see it get entity name, but for me still need those entity names counting and write in to the database. Without using entsel function i mean automaticaly..when you press function in comman line

 

(defun c:bcount    (/ A-VLA-OBJECT CNT ENTITY SS)
 (vl-load-com)
 (setq cnt 0)
 (setq ss (ssget "_X" '((0 . "INSERT"))))
 (if ss
   (progn
     (repeat (sslength ss)
   (setq entity (ssname ss cnt))
   (princ (strcat "\nEntity is a: " ; combine some strings
              (vl-princ-to-string (type entity))
                   ; convert type-output to string
          )
   )
   (princ (strcat "\nThe entity name is: "
              (vl-princ-to-string entity)
          )
   )
   (princ "\nAnd now VLA-data:")
   (setq a-vla-object
          (vlax-ename->vla-object entity)
                   ; convert a ename to a vla-object
   )
   (princ
     (strcat "\nVLA-Entity: " (vl-princ-to-string a-vla-object))
   )
   (setq cnt (1+ cnt))
     )
     (princ (strcat "\nBlocks found: " (itoa cnt)))
     (princ)
   )
 )
)
(c:bcount)

You may find this usefull: http://www.theswamp.org/index.php?topic=43710.0

Link to comment
Share on other sites

well this code a lot warmer, if its possible to choose what name of entity would save ?

 

Not sure what you mean, do you want only blocks with a specific name?

 

Change:

(setq ss (ssget "_X" '((0 . "INSERT"))))

To:

(setq ss (ssget "_X"  (list '(0 . "INSERT")
                           [color=blue]'(2 . "YOUR_BLOCKNAME")[/color])))

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