insert block with objectdbx error

Mark Propst

Usenet Archive
Joined
May 2, 2000
Messages
492
Reaction score
0
Hi
I'm trying to insert a block via objectdbx.
The block gets inserted but the dwg needs recovered to open. The error says linetype not found in symbol table or something to that effect.

any clues what I'm doing wrong here?
this is the function that inserts the block, I assume that's the problem

(defun putblockpt2(doc inBname inbPt space blocksourcedir / rtnobj varpt resitem blockCol) (setq blockCol(vlax-get doc "blocks")) (setq varpt(vlax-make-variant (vlax-3d-point inbPt) vlax-vbvariant) ) (setq resitem (vl-catch-all-apply 'vla-item (list blockCol (vlax-make-variant inbName vlax-vbstring) ) );catch );setq

(if (vl-catch-all-error-p resitem)
(progn
(setq blkDir blocksourcedir)
(setq bfname(strcat blkdir inbname ".dwg"))
(cond
((setq blkFileName(findfile bfname))
(setq inbname blkFileName)
)
(1
(setq inbname nil)
)
);cond
);progn
);if

(if inbname
(progn
(setq rtnobj
(vl-catch-all-apply
'vla-insertblock
(list
space
(vlax-3d-point inbPt)
(vlax-make-variant inbName vlax-vbstring)
(vlax-make-variant 1.0 vlax-vbdouble)
(vlax-make-variant 1.0 vlax-vbdouble)
(vlax-make-variant 1.0 vlax-vbdouble)
(vlax-make-variant 0.0 vlax-vbdouble)
);list
);catch
);rtnobj
(if(vl-catch-all-error-p rtnobj)
(setq rtnobj nil)
)
);progn
);if
rtnobj
)

tia
Mark
 
Mark,
I just tried your routine 3 different ways and all of them work OK without corrupting the drawing.

First try, block exists in the drawing already:
(putblockpt2 doc "mech-02" '(0.0 0.0 0.0) space "..\\")

Second try, block not in drawing but is a file:
(putblockpt2 doc "test" '(0.0 0.0 0.0) space "..\\")

Third, edited the test drawing to have entities with linetypes not loaded in the main drawing (my thinking here was your error message report describing linetype not found):
(putblockpt2 doc "test" '(0.0 0.0 0.0) space "..\\")

So I'm wondering if there is something wrong with the block you are inserting?

And not to pick nits, but I don't see the use of objectdbx here.....

Jeff
 
Hi Jeff,

Jeff Mishler said:
So I'm wondering if there is something wrong with the block you are inserting?

that file seems ok, and as I said, it does get inserted, just that the dwg needs recovered to open. trying to open the file(before recovering) crashes acad with the linetype error message
And not to pick nits, but I don't see the use of objectdbx here.....

this function is just a toolbox func, the dbx routine calls it, as could a non-dbx function. I just thought it might be the insertion function itself, the dbx routine calls that function once the dbx doc is opened. maybe there's something weird in that part, though it works fine in all other respects except for trying to call this function... I'm thinking there's some bug with dbx that doesn't save the drawing correctly after this insertion. I'll try to get time to play with it tomorrow if I get a chance.
thanks for checking

curious, did you use dbx to call the function?
 
curious, did you use dbx to call the function?No, I didn't. SO I went about doing that using this (cut/paste from vlide console):

_$ (vlax-invoke-method oDBX "open" "D:\\Land Projects 3\\newtest.dwg")) nil _$ (setq space (vla-get-modelspace odbx)) #<VLA-OBJECT IAcadModelSpace 01ea06b4> _$ (putblockpt2 odbx "test" '(0.0 0.0 0.0) space "l:\\") #<VLA-OBJECT IAcadBlockReference 01e966e4> _$ (vla-saveas odbx (vla-get-name odbx)) nil _$ (vlax-release-object odbx) 0 _$ odbx #<VLA-OBJECT 00000000> _$ (setq odbx nil) nil _$ odbx nil

and......I was able to open the drawing, no problem, BUT an Audit revealed the following:

Fix any errors detected? [Yes/No] <N>: y

Auditing Block "test" Entities Pass 1

DXF Name Current Value Validation Default Incorrect object linetype (handle 0) changed to ByLayer Incorrect object linetype (handle 0) changed to ByLayer Incorrect object linetype (handle 0) changed to ByLayer Incorrect object linetype (handle 0) changed to ByLayer Incorrect object linetype (handle 0) changed to ByLayer Incorrect object linetype (handle 0)
changed to ByLayer

2 Blocks audited
Pass 1 1 objects audited
Pass 2 1 objects audited

Total errors found 6 fixed 6

Coincidentally the test block has 6 entities in it. So it does appear that ObjectDBX is doing something with the linetypes of the entites in the block.

Strange.....oh, and BTW this is with A2K2.

Good Luck,
Jeff
 
Jeff Mishler said:
No, I didn't. SO I went about doing that using this (cut/paste from vlide console):
and......I was able to open the drawing, no problem, BUT an Audit revealed the following:
Incorrect object linetype (handle 0)
changed to ByLayer

same thing I get with recover.
interesting that you can at least open the dwg without crashing acad,.
ObjectDBX is doing something with the linetypes of the entites in the block.

Strange.....oh, and BTW this is with A2K2.

a2k2 here too.
interesting! glad to know it's not just my usual ignorance causing the problems!

thanks again for checking
Mark
 
Mark,
After playing with this for a while I've found that by opening a second oDBX, oDBX2, for the source file and using the copyobjects method to create the new block in the destination file.....Audit reports no errors. However, the linetypes are still not displayed correctly and I'm at a loss (and out of time for the day) as to why......

But this does get rid of the error, at least in my little test drawings......

This is the revised portion of your code, the entire (if .... ) statement

(if (vl-catch-all-error-p resitem)
(progn ; block doesn't exist, so find it
(setq blkDir blocksourcedir)
(setq bfname(strcat blkdir inbname ".dwg"))
(cond
((setq blkFileName(findfile bfname))
(progn ;;recreate it in doc if found
;(setq inbname blkFileName)
(setq oDBX2 (vla-GetInterfaceObject
*acad* "ObjectDBX.AxDbDocument"))
(vla-open odbx2 blkFileName)
(setq bPoint (vlax-get (vlax-get odbx2 "modelspace") "origin")) (setq newBlk (vlax-invoke-method blockCol "add" (vlax-3d-point bPoint) inbname)) (vlax-for x (vlax-get odbx2 "modelspace") (setq objList (cons x objList))) (setq objArray (vlax-safearray-fill (vlax-make-safearray vlax-vbObject (cons 0 (1- (length objList))) ) objList ) ) (vlax-invoke-method odbx2 "copyobjects" objArray newblk) (vlax-release-object odbx2) (setq odbx2 nil) ) ) (1 (setq inbname nil) ) );cond );progn );if
 
This is way too much work just to insert a block!
:-)
Maybe i'll try in vb.
I had thought about getting a list of the loaded linetypes from the target block drawing with dbx and loading them into the target dwg before trying the insert and had considered your idea of copying the objects...but I was just too sure i must be doing something wrong and that vla-insert should work maybe i'll try vlax-invoke-method tomorrow
 
Hmmm, I just can't stay away from this.

I was just sitting down with a beer and discussing small stuff with my wife when it hit me...I'd changed the linetypes of the entities in my test block to continuous while testing the first try. So I excused myself and went back to my den...

After changing them back to bylayer, purging the base drawing, and retrying it worked flawlessly!

So what I sent DOES work (the copyobjects).

And I'd already tried the vlax-invoke-method with no joy, but left it in due to the thread last summer that you started and Tony T. suggested not using vla- anything with ObjectDBX....

Jeff
BTW, here is my complete test lisp with all of your code that I revised.....

(defun markp
(setq *acad* (vlax-get-acad-object))
(setq oDBX (vla-GetInterfaceObject
*acad* "ObjectDBX.AxDbDocument"))
(vlax-invoke-method oDBX "open" "D:\\Land Projects 3\\newtest.dwg") (setq space (vlax-get oDBX "modelspace")) (putblockpt2 oDBX "test" '(0.0 0.0 0.0) space "L:\\") (vla-saveas oDBX (vla-get-name oDBX)) (vlax-release-object oDBX) (setq oDBX nil *acad* nil space nil)
)

(defun putblockpt2(doc inBname inbPt space blocksourcedir / objArray newblk rtnobj varpt resitem blockCol objList bPoint) (setq blockCol(vlax-get doc "blocks")) (setq varpt(vlax-make-variant (vlax-3d-point inbPt) vlax-vbvariant) ) ;;check for existence of block in doc (setq resitem (vl-catch-all-apply 'vla-item (list blockCol inBname ;(vlax-make-variant inbName vlax-vbstring) ) );catch );setq

(if (vl-catch-all-error-p resitem)
(progn ; block doesn't exist, so find it
(setq blkDir blocksourcedir)
(setq bfname(strcat blkdir inbname ".dwg"))
(cond
((setq blkFileName(findfile bfname))
(progn ;;recreate it in doc if found
;(setq inbname blkFileName)
(setq oDBX2 (vla-GetInterfaceObject
*acad* "ObjectDBX.AxDbDocument"))
(vla-open odbx2 blkFileName)
(setq bPoint (vlax-get (vlax-get odbx2 "modelspace") "origin")) (setq newBlk (vlax-invoke-method blockCol "add" (vlax-3d-point bPoint) inbname)) (vlax-for x (vlax-get odbx2 "modelspace") (setq objList (cons x objList))) (setq objArray (vlax-safearray-fill (vlax-make-safearray vlax-vbObject (cons 0 (1- (length objList))) ) objList ) ) (vlax-invoke-method odbx2 "copyobjects" objArray newblk) (vlax-release-object odbx2) (setq odbx2 nil) ) ) (1 (setq inbname nil) ) );cond );progn );if

(if inbname
(progn
(setq rtnobj
(vl-catch-all-apply
'vlax-invoke-method
(list
space
"insertblock"
(vlax-3d-point inbPt)
inbname
1.0
1.0
1.0
0
;;; not sure why Mark used the following when the above works.... ;;; (vlax-make-variant inbName vlax-vbstring) ;;; (vlax-make-variant 1.0 vlax-vbdouble) ;;; (vlax-make-variant 1.0 vlax-vbdouble) ;;; (vlax-make-variant 1.0 vlax-vbdouble) ;;; (vlax-make-variant 0.0 vlax-vbdouble) );list );catch );rtnobj (if(vl-catch-all-error-p rtnobj) (setq rtnobj nil) ) );progn );if rtnobj )
 
bravo, you did it
doesn't seem like we should *have* to do it this way but what the hey? fwiw vba has the same bug trying to insert

Jeff Mishler said:
Hmmm, I just can't stay away from this.

And I'd already tried the vlax-invoke-method with no joy, but left it in due to the thread last summer that you started and Tony T. suggested not using vla- anything with ObjectDBX....

so much for my memory :-)
Jeff
BTW, here is my complete test lisp with all of your code that I revised.....
;;; not sure why Mark used the following when the above works....
;;; (vlax-make-variant inbName vlax-vbstring)
;;; (vlax-make-variant 1.0 vlax-vbdouble)
;;; (vlax-make-variant 1.0 vlax-vbdouble)
;;; (vlax-make-variant 1.0 vlax-vbdouble)
;;; (vlax-make-variant 0.0 vlax-vbdouble)

dunno, just a left over from trying to get things to work way back when...at some point I thought the straight values weren't working and had to be variants.

Thanks for hammering away on this! Hope your wife is understanding!
:-)~

mark
 
Mark,
Interesting problem. I don't have a solution. Your insertobject code could be simplified a bit though (I think).

Example for a specific drawing:
(setq dbx (vla-getinterfaceobject
(vlax-get-acad-object)
"ObjectDBX.AxDbDocument.16"))

(setq msp (vla-get-modelspace dbx) )

(vlax-invoke msp 'insertblock '(0.0 0.0 0.0) "c:\\arch\\dcb\\tblsix.dwg" 1.0 1.0 1.0 0.0)

(vlax-invoke dbx 'saveas "c:\\junk")

(mapcar 'vlax-release-object (list msp dbx))
 
Mark - It appears that the InsertBlock method may have
some obscure dependence on the drawing editor, and can't be used in ObjectDBX.

However, I would like to try to reproduce your problem
here. If you have a reproducible case or can send me a
small drawing file that causes the error when inserted
via ObjectDBX, I'll have a look at it.

In the mean time, the vla-CopyObjects method seems like a very good workaround (in fact, a number of tools I've done work with blocks and insert DWG files, and they load the file to be inserted into another AxDbDocument and use CopyObjects in order to deal with nested block references).
 
:-)
All my code could be simplified!
all that conversion to variants was just cause when I was first trying to make that function work i kept getting the "no conversion to variant error" with the native lisp types, so I converted them with all that vlax-make-variant mumbo jumbo. eventually it worked but apparently that wasnt' the problem at all since everyone else can get it to work with straight lisp values.
thanks for looking at it
 
Tony,
In general, what I saw with every drawing that I inserted was that, when looking at the resulting block definition, each object in the block definition had a null string for the linetype (probably indicating and unresolved reference). When the block reference was exploded, the linetypes appeared correctly(probably some translation occured via explode). The most obvious visual problems were inserting drawings with non-continuous linetypes. Following post will attach one objectdbx result of mine. I tried opening a template file with all the linetypes already in the table and it still did not act correctly. That is why there are 17 layers.
 

Latest threads

Back
Top