Author Topic: Insert block without opening drawing file.  (Read 1468 times)

0 Members and 1 Guest are viewing this topic.

vincent.r

  • Newt
  • Posts: 101
Insert block without opening drawing file.
« on: August 25, 2023, 08:11:12 AM »
I trying to insert a block & explode it, without opening the drawing. I am using Lee Mac's ODBX Wrapper. Modified as -

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test1 (/)
  2.   (LM:ODBX
  3.     (function
  4.       (lambda (doc)
  5.                 (vla-insertblock
  6.                   (vla-get-modelspace
  7.                     (vla-get-activedocument (vlax-get-acad-object)))
  8.                   (vlax-3d-point '(0 0 0))
  9.                   "C:\\Users\\vincent.r\\Desktop\\blocks\\REVERSIBLE.dwg"
  10.                   1
  11.                   1
  12.                   1
  13.                   0
  14.                 )
  15.       )
  16.     )
  17.     nil
  18.     t
  19.   )
  20.   (princ)
  21. )

It's not working & returning message - Duplicate definition of block THV  ignored.
Duplicate definition of block MAINS_CONNECTION  ignored.

I am okay by keeping block inside the drawing (not purged) and insert it.
Anybody knows, how to get it done? Drawing file and block attached.

Thanks in advance.
Vincent


EDIT (John): Added code tags.
« Last Edit: August 25, 2023, 11:19:05 AM by JohnK »

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Insert block without opening drawing file.
« Reply #1 on: August 25, 2023, 09:34:36 AM »
You are invoking the insertblock method on the activedocument object (i.e. the current drawing), not the ODBX document.

Change:
Code - Auto/Visual Lisp: [Select]
To:
Code - Auto/Visual Lisp: [Select]
  1. doc

Though, if I recall correctly, you may need to access the layout container block via the layouts collection (then vla-get-block) or blocks collection.

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Insert block without opening drawing file.
« Reply #2 on: August 25, 2023, 11:56:19 AM »
You mean this, Lee...

Code - Auto/Visual Lisp: [Select]
  1.     (defun c:test1 (/)
  2.       (LM:ODBX
  3.         (function
  4.           (lambda (doc)
  5.                     (vla-insertblock
  6.                       (vla-get-block
  7.                         (vla-get-activelayout doc))
  8.                       (vlax-3d-point '(0 0 0))
  9.                       "C:\\Users\\vincent.r\\Desktop\\blocks\\REVERSIBLE.dwg"
  10.                       1
  11.                       1
  12.                       1
  13.                       0
  14.                     )
  15.           )
  16.         )
  17.         nil
  18.         t
  19.       )
  20.       (princ)
  21.     )
  22.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Insert block without opening drawing file.
« Reply #3 on: August 25, 2023, 12:04:43 PM »
The activelayout may not necessarily correspond to Modelspace.

vincent.r

  • Newt
  • Posts: 101
Re: Insert block without opening drawing file.
« Reply #4 on: August 25, 2023, 01:30:37 PM »
You mean this, Lee...

Code - Auto/Visual Lisp: [Select]
  1.     (defun c:test1 (/)
  2.       (LM:ODBX
  3.         (function
  4.           (lambda (doc)
  5.                     (vla-insertblock
  6.                       (vla-get-block
  7.                         (vla-get-activelayout doc))
  8.                       (vlax-3d-point '(0 0 0))
  9.                       "C:\\Users\\vincent.r\\Desktop\\blocks\\REVERSIBLE.dwg"
  10.                       1
  11.                       1
  12.                       1
  13.                       0
  14.                     )
  15.           )
  16.         )
  17.         nil
  18.         t
  19.       )
  20.       (princ)
  21.     )
  22.  

Thanks Ribarm. Instead of full path & the blockname I just mentioned the block name "REVERSIBLE". It works great.

vincent.r

  • Newt
  • Posts: 101
Re: Insert block without opening drawing file.
« Reply #5 on: August 25, 2023, 01:49:18 PM »
You are invoking the insertblock method on the activedocument object (i.e. the current drawing), not the ODBX document.

Change:
Code - Auto/Visual Lisp: [Select]
To:
Code - Auto/Visual Lisp: [Select]
  1. doc

Though, if I recall correctly, you may need to access the layout container block via the layouts collection (then vla-get-block) or blocks collection.

Thanks Lee. Now I am able to insert block in unopened drawing. but not able get just inserted or last inserted block. I want to set visibility to it.
Earlier block is now a dynamic block. Block named "REVERSIBLE" is in the attached drawing.

Any help on set visibility will be much appreciated.
« Last Edit: August 25, 2023, 01:54:34 PM by vincent.r »

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Insert block without opening drawing file.
« Reply #6 on: August 25, 2023, 07:46:25 PM »
You are invoking the insertblock method on the activedocument object (i.e. the current drawing), not the ODBX document.

Change:
Code - Auto/Visual Lisp: [Select]
To:
Code - Auto/Visual Lisp: [Select]
  1. doc

Though, if I recall correctly, you may need to access the layout container block via the layouts collection (then vla-get-block) or blocks collection.

Thanks Lee. Now I am able to insert block in unopened drawing. but not able get just inserted or last inserted block. I want to set visibility to it.
Earlier block is now a dynamic block. Block named "REVERSIBLE" is in the attached drawing.

Any help on set visibility will be much appreciated.

The vla-insertblock method will return the inserted block reference object.

vincent.r

  • Newt
  • Posts: 101
Re: Insert block without opening drawing file.
« Reply #7 on: August 26, 2023, 04:12:12 AM »
You are invoking the insertblock method on the activedocument object (i.e. the current drawing), not the ODBX document.

Change:
Code - Auto/Visual Lisp: [Select]
To:
Code - Auto/Visual Lisp: [Select]
  1. doc

Though, if I recall correctly, you may need to access the layout container block via the layouts collection (then vla-get-block) or blocks collection.

Thanks Lee. Now I am able to insert block in unopened drawing. but not able get just inserted or last inserted block. I want to set visibility to it.
Earlier block is now a dynamic block. Block named "REVERSIBLE" is in the attached drawing.

Any help on set visibility will be much appreciated.

The vla-insertblock method will return the inserted block reference object.

Thanks Lee. I will work on it & let you know the results.