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

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

jshipley
Advocate Advocate
1,930 Views
9 Replies
Message 1 of 10

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

jshipley
Advocate
Advocate

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

 

0 Likes
Accepted solutions (1)
1,931 Views
9 Replies
Replies (9)
Message 2 of 10

jshipley
Advocate
Advocate

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

0 Likes
Message 3 of 10

chiefbraincloud
Collaborator
Collaborator
Accepted solution

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
0 Likes
Message 4 of 10

jshipley
Advocate
Advocate

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

0 Likes
Message 5 of 10

kerry_w_brown
Mentor
Mentor

@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 )  🙂

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 6 of 10

chiefbraincloud
Collaborator
Collaborator

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
0 Likes
Message 7 of 10

Anonymous
Not applicable

@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

 

 


 


 

0 Likes
Message 8 of 10

kerry_w_brown
Mentor
Mentor

 

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


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
Message 9 of 10

chiefbraincloud
Collaborator
Collaborator

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
0 Likes
Message 10 of 10

jeff
Collaborator
Collaborator

 

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

 

 

Edited by
Discussion_Admin

 

 

 

You can also find your answers @ TheSwamp
0 Likes