Author Topic: AutoMagic Needed: Updating Blocks Inserts Definitions  (Read 2330 times)

0 Members and 1 Guest are viewing this topic.

Chillme1

  • Newt
  • Posts: 57
  • Must learn to earn!
AutoMagic Needed: Updating Blocks Inserts Definitions
« on: October 05, 2012, 06:47:52 AM »
I have a quandry about block inserts.
The standard AutoCAD tools seem to do what is required some of the time.
I do not have a compiled list of specific instances yet but am assembling some notes on when they (AutoCAD ATTSYNC, etc.) do not work.
I do know that I would like a rock solid block insert redefinition (or updating) routine and would like to know more about how to code via VLISP to perform the following actions:

1a.) Select all blocks and make sure their latest definitions are being located and 'read in' to the current file from a specified directory(ies).

1b.) Tips on creating a batch routine that would accomplish the above action.

2.) Affect copied block inserts in a file (which now I understand is not the 'proper' thing to do); convert these copies  (with an anonymous name) back to their real name.
(I think I have some info about anonymous conversions already :ugly:)

I hope that you can shed light on any or all of the above items.
 
Thanks, Clint
Mechanical Designer / Process Piping
AutoCAD Toolsets 2022
Newbie Betimes - LISP Programmer

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: AutoMagic Needed: Updating Blocks Inserts Definitions
« Reply #1 on: October 05, 2012, 09:16:05 AM »
Quote
1a.) Select all blocks and make sure their latest definitions are being located and 'read in' to the current file from a specified directory(ies).

Sounds like XREF?  Or do these blocks have attributes associated? 
James Buzbee
Windows 8

mkweaver

  • Bull Frog
  • Posts: 352
Re: AutoMagic Needed: Updating Blocks Inserts Definitions
« Reply #2 on: October 05, 2012, 11:25:52 AM »
I agree with James, if your blocks don't have attributes simply make them xrefs.

For attributed blocks, I use this:
Code: [Select]
(defun C:ReloadBlock( / expert ss1 ssl inserts blocks oblock)
  (setq expert (getvar "expert"))
  (setq ss1 (ssget '((0 . "insert")))
ssl (sslength ss1))
  (setq inserts
(apply 'append (setq inserts (ssnamex ss1)))
inserts (vl-remove-if-not
  (function
    (lambda(x)
      (= 'ENAME (type x))
      )
    )
  inserts
  )
inserts (mapcar (function (lambda(x)
    (setq oblock (vlax-ename->vla-object x))
    (if (vlax-property-available-p oblock "effectivename")
      (vla-get-effectivename oblock)
      (vla-getname oblock)
      )
    )
  )
inserts
)
inserts (vl-sort inserts '<)
blocks (vla-get-blocks (vla-get-activedocument(vlax-get-acad-object)))
)
  (setvar "expert" 5)
  (foreach bname inserts
    (setq oblock (vla-item blocks bname))
    (cond
      ((= :vlax-true (vla-get-isxref oblock))
       nil
       )
      (T
       (if (findfile (strcat bname ".dwg"))
(progn
   (command "._insert" (strcat bname "="))
   (command)
   (command "._attsync" "n" bname)
   )
(princ (strcat "\NCan't find an external definition for " bname "."))
)
       )
      )
    )
  (setvar "expert" expert)
  (princ)
  )

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: AutoMagic Needed: Updating Blocks Inserts Definitions
« Reply #3 on: October 05, 2012, 12:30:10 PM »
Guys, these are likely for P&ID drawings, so XREFs are a nice outside-the-box solution but ultimately not a good answer.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Chillme1

  • Newt
  • Posts: 57
  • Must learn to earn!
Re: AutoMagic Needed: Updating Blocks Inserts Definitions
« Reply #4 on: October 05, 2012, 01:32:42 PM »

Our esteemed colleague, 'dgorman', is correct in that I would like to keep the blocks as such.
I finally found code that may just do the trick.
I have not yet tested the following routine but would appreciate any comments or further advice after your review of it.

Code - Auto/Visual Lisp: [Select]
  1. ;Following LISP example code By Peter Jamtgaard on 10/31/11 on WAUN LISP group
  2.  
  3. (defun C:UPDATE (/
  4.                    objSelection
  5.                    ssSelections
  6.                    strBlockName
  7.                    strFileName
  8.                 )
  9.  (princ "\nSelect Block to be updated: ")  (if (and (setq ssSelections (ssget ":E:S" (list (cons 0 "insert"))))
  10.           (setq objSelection (vlax-ename->vla-object
  11.                               (ssname ssSelections 0)))
  12.           (setq strBlockName (vla-get-effectivename objSelection))
  13.           (setq strFileName  (strcat strBlockName ".dwg"))
  14.           (findfile strFileName)
  15.      )
  16.   (progn
  17.    (command "-insert" (strcat strBlockName "=") "0,0")
  18.    (while (= (getvar "cmdactive") 1)
  19.     (command "")
  20.    )
  21.    (entdel (entlast))
  22.   )
  23.   (princ "\nError: ")
  24.  )
  25.  (prin1)
  26. )

Would any particular line require modification to perform the update I described earlier?
Thanks, Clint
Mechanical Designer / Process Piping
AutoCAD Toolsets 2022
Newbie Betimes - LISP Programmer

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

mkweaver

  • Bull Frog
  • Posts: 352
Re: AutoMagic Needed: Updating Blocks Inserts Definitions
« Reply #6 on: October 05, 2012, 05:10:03 PM »
Does the reloadblock routine I provided above update blocks the way you want?  If so, it would be easy to modify have it update all block insertions.

Chillme1

  • Newt
  • Posts: 57
  • Must learn to earn!
Re: AutoMagic Needed: Updating Blocks Inserts Definitions
« Reply #7 on: October 11, 2012, 02:28:42 PM »
Hello again mkweaver,

I apologize for the extended delay as I am not getting much time to test available code nor responding to you.
I will have a window next week (October 15 - 18) and will try it then and let you know ASAP.

I DO appreciate your interest.
Thanks, Clint
Mechanical Designer / Process Piping
AutoCAD Toolsets 2022
Newbie Betimes - LISP Programmer

Chillme1

  • Newt
  • Posts: 57
  • Must learn to earn!
Re: AutoMagic Needed: Updating Blocks Inserts Definitions
« Reply #8 on: October 15, 2012, 07:50:36 AM »
Anticipate a delay for yet another week due to workload. It is nice to have a good job/career!
Thanks, Clint
Mechanical Designer / Process Piping
AutoCAD Toolsets 2022
Newbie Betimes - LISP Programmer

mkweaver

  • Bull Frog
  • Posts: 352
Re: AutoMagic Needed: Updating Blocks Inserts Definitions
« Reply #9 on: October 15, 2012, 10:24:31 AM »
Anticipate a delay for yet another week due to workload. It is nice to have a good job/career!
I agree, it is nice to have a good job.