Author Topic: Replace Block w/ DB, Modify DB's Properties  (Read 3054 times)

0 Members and 1 Guest are viewing this topic.

stusic

  • Guest
Replace Block w/ DB, Modify DB's Properties
« on: April 26, 2012, 12:57:17 PM »
I got so much help with my last few issues, I thought I'd throw out another problem I think this community could help me with.

Our office uses attributed blocks that contain part information to tag equipment. The problem is that there isn't one block, but 8 different blocks - which one is used depends on the position of the tag relative to the equipment (i.e., top, top-left, top-right, left, right, bottom-left, bottom-right, bottom).

I've created a dynamic block that can replace these blocks, but when I replace an old tag, the block/leader isn't always oriented correctly relative to the orientation of the old tag.

So I'd like to have a routine that replaces the old blocks, but looks at which block it is and modifies its flipstate and leader endpoint to match that of the old block.

I hope that makes a little sense. I've included a drawing that should help explain...

Any direction on this would be great. I've found very little on modifying dynamic block properties.

Thanks All :)

pBe

  • Bull Frog
  • Posts: 402
Re: Replace Block w/ DB, Modify DB's Properties
« Reply #1 on: April 30, 2012, 08:10:24 AM »
I'm thinking this is a "repair" job. If it is then:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Demo ( / _AttFunc ss i fnd nm rb val cval)
  2. (defun _AttFunc  (en lst / vals v)
  3.         (setq vals (list (vla-get-tagstring at)(vla-get-textstring at)))
  4.                 (if (and lst (setq v (assoc (car vals) lst)))
  5.                         (vla-put-textstring at (cadr v))) vals))
  6.                       (vlax-invoke (if (eq (type en) 'VLA-OBJECT)
  7.                                   en (vlax-ename->vla-object en)) 'Getattributes)
  8.         )
  9.   )
  10. (if     (and (tblsearch "BLOCK" "DB_Baloon")
  11.         (setq ss (ssget "_X" (list '(0 . "INSERT")'(66 . 1)
  12.                                 '(2 . "Balloon_*")(cons 410 (getvar 'Ctab))))))
  13.         (repeat (setq i (sslength ss))
  14.          (setq a (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
  15.         (cond ((and
  16.            (setq fnd (assoc
  17.                      (setq nm (vla-get-effectivename a))
  18.         '(("Balloon_TR"  (1.0493 0.8618))  ("Balloon_TL"  (-1.0493 0.8618))
  19.         ("Balloon_R"   (1.4062 0.0)) ("Balloon_L"         (-1.4062 0.0))
  20.         ("Balloon_T"   (0.0  1.5937)) ("Balloon_B"   (0.0  -1.5937))
  21.         ("Balloon_BL"  (-1.0493 -0.8618)) ("Balloon_BR"  (1.0493 -0.8618))))
  22.                    )
  23.            (setq rb (vlax-invoke (vlax-get  (vla-get-ActiveLayout
  24.                      (vla-get-activedocument (vlax-get-acad-object)))
  25.                      'Block) 'InsertBlock  (vlax-get a 'InsertionPoint)
  26.                                   "DB_Baloon"
  27.                                    1 1 1 0))
  28.            (setq val (car (vl-remove-if-not
  29.                              '(lambda (x)
  30.                                 (eq (vla-get-PropertyName
  31.                                       x ) "Visibility"))
  32.                              (vlax-invoke rb
  33.                                'getdynamicblockproperties
  34.                              ))
  35.                            )
  36.                 )
  37.            (not (vlax-put val 'Value nm))
  38.            (setq Cval (_AttFunc a nil))
  39.            (_AttFunc RB Cval)
  40.            (not (vla-delete a))
  41.            (vla-move  rb (vlax-3d-point  '(0.0 0.0))
  42.                         (vlax-3d-point (cadr fnd)))
  43.                         ))
  44.                 )
  45.         )
  46.         )(princ)
  47.   )

I wasnt able to use your Dynamic Block, When i converted the file use DWGTrueView  all DB properties disappears. The code above contains visibility but no flipstate.
What i did is use the current block name as values for visibility parameter
Code: [Select]
(("Balloon_TR"  (1.0493 0.8618))  ("Balloon_TL"  (-1.0493 0.8618))
("Balloon_R"   (1.4062 0.0)) ("Balloon_L"   (-1.4062 0.0))
("Balloon_T"   (0.0  1.5937)) ("Balloon_B"   (0.0  -1.5937))
("Balloon_BL"  (-1.0493 -0.8618)) ("Balloon_BR"  (1.0493 -0.8618))))

Since i used the center of the block as insertion to maintain a  single instance of the attdef per visibility , the point of the arrow needs to be on the same spot as the one before.
the point list represents the distance between the original insertion point from the new ins point of the the inserted DB per block name

I atached the file where i used the posted demo routine .

HTH

[CODE re-posted]
« Last Edit: May 19, 2012, 11:14:13 PM by pBe »

stusic

  • Guest
Re: Replace Block w/ DB, Modify DB's Properties
« Reply #2 on: May 19, 2012, 09:45:47 AM »
Thank you for your help. When I get some time, I'll see what those numbers next to the block name mean and try to apply that to some code.

Thanks Again,

-stu

stusic

  • Guest
Re: Replace Block w/ DB, Modify DB's Properties
« Reply #3 on: May 19, 2012, 09:54:07 AM »
Code: [Select]
(("Balloon_TR"  (1.0493 0.8618)))Since i used the center of the block as insertion to maintain a  single instance of the attdef per visibility , the point of the arrow needs to be on the same spot as the one before.
the point list represents the distance between the original insertion point from the new ins point of the the inserted DB per block name

So this simply offsets the insertion point? I don't think I understand. Where does any modification of dynamic properties come into play?

However, I've been moved away on to other tasks and must get back to this at a later date. I appreciate your help though and will see if I can figure out how to use the point list you included.

Thanks a bunch, pBe

pBe

  • Bull Frog
  • Posts: 402
Re: Replace Block w/ DB, Modify DB's Properties
« Reply #4 on: May 19, 2012, 09:59:34 AM »
Thank you for your help. When I get some time, I'll see what those numbers next to the block name mean and try to apply that to some code.

Thanks Again,

-stu

It wont do you any good stu, I removed the code for the reason that all i heard are  "crickets" 2 weeks after i replied to your Q.

Dont worry about it.

One more thing. for the love of gravy, i cant even remenber what the code looks like now and what it does

« Last Edit: May 19, 2012, 10:05:42 AM by pBe »

pBe

  • Bull Frog
  • Posts: 402
Re: Replace Block w/ DB, Modify DB's Properties
« Reply #5 on: May 19, 2012, 11:12:59 PM »
CODE reposted.

Try the code with the attached DWG file on post #2 [DBDemo.dwg]

(("Balloon_TR"  (1.0493 0.8618)) <--- the point list on this case will be the basis for the move as i used a different insertion point on the block i used for ths demo.

HTH

stusic

  • Guest
Re: Replace Block w/ DB, Modify DB's Properties
« Reply #6 on: May 21, 2012, 09:17:52 AM »
With a new baby in the house, trying to move to another city, working 70+ hours a week, and my boss moving me from project to project, I apologize for not making it back within your time limit.

I have changed my default notification for this forum to instant email notification, so maybe I'll be able to provide a faster response to those with arbitrary time limits on their help.

Thank you for reposting your code, maybe it can be beneficial to someone looking for something similar.

pBe

  • Bull Frog
  • Posts: 402
Re: Replace Block w/ DB, Modify DB's Properties
« Reply #7 on: May 21, 2012, 10:08:45 AM »
With a new baby in the house, trying to move to another city, working 70+ hours a week, and my boss moving me from project to project, I apologize for not making it back within your time limit.

I have changed my default notification for this forum to instant email notification, so maybe I'll be able to provide a faster response to those with arbitrary time limits on their help.

Thank you for reposting your code, maybe it can be beneficial to someone looking for something similar.

First fo all , congratulations on your  fatherhood.  :-)

Dont worry about the code. But i guess its not gonna be generic, its has a very specific conditions. But no matter. we're cool

Cheers, and congratulation again Phillip  :-)