Author Topic: Get Block  (Read 21411 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #30 on: March 15, 2006, 01:07:43 AM »
Good Night. :-)
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.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Re: Get Block
« Reply #31 on: March 15, 2006, 01:10:46 AM »
:lmao:

Can I say "it depends", and get away with it ?

Only if you're "John Glenn".
I drink beer and I know things....

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #32 on: March 15, 2006, 02:17:08 AM »
That is why you don't insert the block, but just get the name of the block from the drawing, and the get the definition from the block table (collection), and copy all the objects from there to the new drawing.  Create a blank drawing with the name being the same as the block, and then open it with ObjectDBX and copy from the base drawing into the new one.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Get Block
« Reply #33 on: March 15, 2006, 02:58:33 AM »
Tim, while that is one way to do this (although creating it first then opening with ObjectDBX is not necessary....I'll let you think on that ;-) ) I think it is beyond the scope of a beginner program which is why I suggested wblock. With wblock you can specify a Block name to export and it will take the BlockDefinition and create a new drawing with the name specified.

Alan, I would think that for a block Library, which was mentioned in the first post, you'd want the blockdef not an inserted version of it. Otherwise you'd want to rename it accordingly for the different variations that can be made from it.

I gotta remember that Kerry is up while the rest of us should be sleeping..... :kewl:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #34 on: March 15, 2006, 08:45:28 AM »
Kerry,
Well I seldom use wblock & had allways select an object, not realizing the block NAME used the block definition. That does make matter simpler. Thanks Kerry for the code which explains everything. Now do you want to explain that to someone who has never written a lisp? :)

I'm waiting to see if Tim can come up with Jeff's riddle, as I don't have the answer. 8-)
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #35 on: March 15, 2006, 11:08:29 AM »
Tim, while that is one way to do this (although creating it first then opening with ObjectDBX is not necessary....I'll let you think on that ;-) ) I think it is beyond the scope of a beginner program which is why I suggested wblock. With wblock you can specify a Block name to export and it will take the BlockDefinition and create a new drawing with the name specified.
I'm waiting to see if Tim can come up with Jeff's riddle, as I don't have the answer. 8-)
Give me a minute.  I need to get my thinking cap on.

I coded one up real fast yesterday with the insert explode wblock out, all with ActiveX methods, but was getting some kind of error, and I had to go home, so I couldn't work on it anymore.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #36 on: March 15, 2006, 11:17:07 AM »
.................  the code which explains everything. Now do you want to explain that to someone who has never written a lisp? :)


I had thought that the Joker may like to attempt to explain the code.  ... I can't think of a better way to learn, one line at a time.
Maybe you can tell him where to get the information, since you used (vlax.... stuff.  I know lispers that don't know where to get that info.

Okay... I will tell..
Click help
Click AutoLISP, Visual LISP, and DXF
Then on the right side click "AutoLISP Reference"
Then go to ActiveX and VBA Reference.

That is how I do it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #37 on: March 15, 2006, 11:31:53 AM »
Tim, while that is one way to do this (although creating it first then opening with ObjectDBX is not necessary....I'll let you think on that ;-) )
The only way I can think of right now that might work is to do it the way I did it in my code yesterday.  Use the WBlock method on the active document for all the objects in the blocks definition.  I can't think of a way to use ObjectDBX any other way.

... or, load it into the VLIDE, select any command you want help with, press CTRL+F1 .. there are only about 20 functions used in that routine.


and "The Visual Lisp Developer's Bible" by David M. Stein .. I think Jeff has a copy on this site somewhere, or google it, or look for it at Customer Files on the AutoDesk Newsgroups

Good point.  I don't use the vlide, so I wouldn't have thought of that.  I code in notepad.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Get Block
« Reply #38 on: March 15, 2006, 11:58:59 AM »
Tim, while that is one way to do this (although creating it first then opening with ObjectDBX is not necessary....I'll let you think on that ;-) )
I can't think of a way to use ObjectDBX any other way.
HINT - Create an Instance of ObjectDBX...
Code: [Select]
(setq odbx (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument.16") )
now use (vlax-dump-object odbx t)......look familiar? If not, compare it to a dump of the ActiveDocument......

BTW, using the VLIDE makes it real easy to check these things on the fly.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #39 on: March 15, 2006, 12:25:34 PM »
Tim, while that is one way to do this (although creating it first then opening with ObjectDBX is not necessary....I'll let you think on that ;-) )
I can't think of a way to use ObjectDBX any other way.
HINT - Create an Instance of ObjectDBX...
Code: [Select]
(setq odbx (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument.16") )
now use (vlax-dump-object odbx t)......look familiar? If not, compare it to a dump of the ActiveDocument......

BTW, using the VLIDE makes it real easy to check these things on the fly.
I still don't see it oh Master of the ObjectDBX...... Teach me so that I might learn the secrets of it also.

I know that T.T. did something with ObjectDBX to clone a block in the same drawing, but I never looked at the code.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Get Block
« Reply #40 on: March 15, 2006, 01:31:23 PM »
OK, here ya go Tim.
Code: [Select]
(defun c:myWblock (/ *acad *doc bname bpath ent_list lay ms odbx)
  (if (and (setq *acad (vlax-get-acad-object))
   (setq *doc (vla-get-activedocument *acad))
   (setq bname (getstring "\nBlock name to save to Library: "))
   (tblsearch "BLOCK" bname)
   (setq bPath (findfile (getstring t "\nLibrary Path: ")))
   )
    (progn
      (setq odbx (if (< (atoi (substr (getvar "acadver") 1 2)) 16)
   (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
   (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument.16"))
    )
      (vlax-for ent (vla-item (vla-get-blocks *doc) bname)
(setq ent_list (cons ent ent_list))
)
      (setq ent_list (reverse ent_list))
      (vlax-invoke *doc 'copyobjects ent_list (setq ms (vla-get-modelspace odbx)) 'pairs)
      (vlax-for ent ms
(setq lay (vla-item (vla-get-layers odbx) (vla-get-layer ent)))
(vla-put-color ent (vla-get-color lay))
(vla-put-linetype ent "ByBlock")
(vla-put-layer ent "0")
)
      (vlax-for lay (vla-get-layers odbx)
(vl-catch-all-apply '(lambda ()
       (vla-delete lay)
       ))
)
      (vla-saveas odbx (strcat bPath "\\" bname ".dwg"))
      (vlax-release-object odbx)
      (vlax-release-object *doc)
      (vlax-release-object *acad)
      )
    )
  (princ)
  )

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #41 on: March 15, 2006, 01:39:58 PM »
Okay.  My wording was wrong.  I would have done it the same way.  Good code Jeff, as always.

Since everyone is posting code, I guess I will post mine also. :evil:
Right now the block path is hard coded to "C:\temp\".
Code: [Select]
(defun c:ExportBlock (/ ActDoc CurSpace ss Ent BlkName BlkNameList tmpObj tmpss tmpObjList BlkDir FullPath)

(vl-load-com)
(setq BlkDir "C:/temp/")
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq CurSpace
 (vlax-get
  ActDoc
  (if (equal (getvar "cvport") 1)
   'PaperSpace
   'ModelSpace
  )
 )
)
(setq ssCol (vla-get-SelectionSets ActDoc))
(if (setq ss (ssget '((0 . "INSERT"))))
 (while (setq Ent (ssname ss 0))
  (setq BlkName (cdr (assoc 2 (entget Ent))))
  (if
   (and
    (not (vl-position BlkName BlkNameList))
    (/= (substr BlkName 1 1) "*")
   )
   (progn
    (setq BlkNameList (cons BlkName BlkNameList))
    (setq tmpObj
     (vlax-invoke
      CurSpace
      'InsertBlock
      '(0.0 0.0 0.0)
      BlkName
      1.0
      1.0
      1.0
      0.0
     )
    )
    (setq tmpss (vla-Add ssCol "tmpss"))
    (foreach Obj (setq tmpObjList (vlax-invoke tmpObj 'Explode))
     (vla-put-Layer Obj "0")
     (vla-put-Color Obj acByBlock)
     (vla-put-Linetype Obj "ByBlock")
    )
    (vla-AddItems tmpss
     (vlax-make-variant
      (vlax-safearray-fill
       (vlax-make-safearray vlax-vbObject (cons 0 (1- (length tmpObjList))))
       tmpObjList
      )
     )
    )
    (if (findfile (setq FullPath (strcat BlkDir BlkName ".dwg")))
     (progn
      (initget "Yes No")
      (if (/= (getkword (strcat "\n Block \"" BlkName "\" aready exist.  Wish to overwrite it [<Y>es No]: ")) "No")
       (vlax-invoke ActDoc 'WBlock FullPath tmpss)
      )
     )
    )
    (foreach Obj tmpObjList
     (vla-Delete Obj)
    )
    (vla-Delete tmpObj)
    (vla-Delete tmpss)
    (setq tmpss nil)
   )
  )
  (ssdel Ent ss)
 )
)
(if BlkNameList
 (progn
  (textscr)
  (prompt "\n - Created drawings in \"C:\\Temp\\\" for following blocks: ")
  (foreach i BlkNameList
   (prompt (strcat "\n  " i))
  )
 )
)
(princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Get Block
« Reply #42 on: March 15, 2006, 04:14:49 PM »
I'm waiting to see if Tim can come up with Jeff's riddle, as I don't have the answer. 8-)
Alan, in case you still don't see what I was alluding to:
When you create an ObjectDBX object, it IS a new blank drawing (and I do mean Blank, as I'm pretty sure it does not use any template) so you can immediately just copy the block objects into the modelspace of that document and save. This now gives you the drawing you need without having to create, save, open in ObjectDBX & copy the objects into it, as Tim was saying.

IOW, since Tim was referencing ObjectDBX for a portion of the job, I was just pointing out that it could be used for the entire job.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #43 on: March 15, 2006, 04:33:55 PM »
Thanks Jeff, that is good to know. That ObjectDBX stuff is still quite the mystery to me.
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.

Joker

  • Guest
Re: Get Block
« Reply #44 on: March 16, 2006, 01:10:45 PM »
You guys are moving faster than I I can figure things out.