.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to insert block, not on drawing, in search path

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
jshipley
1239 Views, 9 Replies

How to insert block, not on drawing, in search path

I am trying to insert a block (using .Net) that does not already exist on the drawing.  It is on a network share, which is in the search path.  If I, from the command line insert the block, it finds it ok and inserts it.  But when I do this from .Net code it does not search for the block.  So how do you get it to search for the block and insert it?

 

Here is a code snippet I'm using to insert the block:

 

Dim myDwg AsDocument = Application.DocumentManager.MdiActiveDocument

 

Using myDocLock AsDocumentLock= myDwg.LockDocument()

 

Using myTrans AsTransaction= myDwg.TransactionManager.StartTransaction

 

'Open the database for WriteDim myBT AsBlockTable = CType(myDwg.Database.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)

 

Dim myModelSpace AsBlockTableRecord = CType(myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite), BlockTableRecord)

 

'Insert the BlockDim myBlockDef AsBlockTableRecord = CType(myBT(BlockName).GetObject(OpenMode.ForRead), BlockTableRecord)

 

Dim myBlockRef AsNew DatabaseServices.BlockReference(InsertPoint, myBT(BlockName))

myBlockRef.ScaleFactors =

New Geometry.Scale3d(XScale, YScale, ZScale)

myModelSpace.AppendEntity(myBlockRef)

myTrans.AddNewlyCreatedDBObject(myBlockRef,

True)

myBlkID = myBlockRef.ObjectId

 

 

Thanks in advance,

Jim

 

Tags (3)
9 REPLIES 9
Message 2 of 10
jshipley
in reply to: jshipley

Well after more searching, it looks like this has been covered over in 'The Swamp'...

http://www.theswamp.org/index.php?topic=37686.0

 

Thanks

Message 3 of 10
chiefbraincloud
in reply to: jshipley

Well, there's lots of block stuff on that thread at the Swamp, but unless I missed it when I browsed through the posts, none of them help you out with your actual question of how to find a block in AutoCad's Support File Search Path.

 

Dim path As String = HostApplicationServices.Current.FindFile(FileName, acdocs.MdiActiveDocument.Database, FindFileHint.Default)

 

Do put that into a Try/Catch, because it throws some kind of exception if no file is found.

 

Of course, once you know the path to the block, the way to insert it into the current drawing is covered on the Swamp thread.

Dave O.                                                                  Sig-Logos32.png
Message 4 of 10
jshipley
in reply to: chiefbraincloud

Cool - thanks, that's what I was looking for

Message 5 of 10
kdub_nz
in reply to: chiefbraincloud


@chiefbraincloud wrote:

Well, there's lots of block stuff on that thread at the Swamp, but unless I missed it when I browsed through the posts, none of them help you out with your actual question of how to find a block in AutoCad's Support File Search Path.

 

 

You probably missed the FindFile Method references .... as you said, it's a full thread ( though still not complete yet )  🙂

 

//

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 6 of 10
chiefbraincloud
in reply to: kdub_nz

Kerry, I meant no disrespect, It is a long thread, with a lot of good information.  If it's there then I appologize, I just didn't see it, (and perhaps I couldn't see it, since I am not a member of the Swamp)

Dave O.                                                                  Sig-Logos32.png
Message 7 of 10
ButterFlyShame
in reply to: kdub_nz


@KerryBrown wrote:

@chiefbraincloud wrote:

Well, there's lots of block stuff on that thread at the Swamp, but unless I missed it when I browsed through the posts, none of them help you out with your actual question of how to find a block in AutoCad's Support File Search Path.

 

 

You probably missed the FindFile Method references .... as you said, it's a full thread ( though still not complete yet )  🙂

 

 

==========================================================

 Fix that Search Engine  in Swamp,( Never found anything using search)

 I never got any answer from Swamp.There are only 4 active members there , all of them, keep the codes in secret. And answering nonsense .

 

Chief is an active member and I have lots of respect for him  , helped me personally a lot.

 

 

 

Edited by
Discussion_Admin

 

 


 


 

Message 8 of 10
kdub_nz
in reply to: ButterFlyShame

 

ButterFlyShame,

  Thank you for your generous comments.

  What name do you use at TheSwamp ... just so I can recognise you when you ask a question there.

 

Regards

Kerry Brown

//

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 9 of 10
chiefbraincloud
in reply to: kdub_nz

Kerry,

 

 I might make my own complaints about the Swamp, but if I were to do so, I would make them on the Swamp, not here.

 

And I applaud your restraint in your reply.  No need to start eFights here.

 

For what it's worth, after looking again at the thread on the swamp, I had failed to notice that there were three pages.  I had only read the first page.

 

 

Edited by
Discussion_Admin

Dave O.                                                                  Sig-Logos32.png
Message 10 of 10
jeff
in reply to: chiefbraincloud

 

 I will stop here before I say something to get me kicked off.

 

 

Edited by
Discussion_Admin

 

 

 

You can also find your answers @ TheSwamp

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost