.NET

.NET

Reply
Active Contributor
30 Posts
0 Kudos
Registered: ‎11-01-2006
Post 1 of 10
Accepted Solution

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

734 Views, 9 Replies
09-16-2011 07:49 AM

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

 

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.

Active Contributor
30 Posts
0 Kudos
Registered: ‎11-01-2006
Post 2 of 10

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

09-16-2011 09:03 AM 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

*Expert Elite*
753 Posts
54 Kudos
Registered: ‎02-13-2008
Post 3 of 10

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

09-16-2011 12:17 PM 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
Active Contributor
30 Posts
0 Kudos
Registered: ‎11-01-2006
Post 4 of 10

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

09-16-2011 12:19 PM in reply to: chiefbraincloud

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

Valued Mentor
278 Posts
22 Kudos
Registered: ‎11-29-2008
Post 5 of 10

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

09-16-2011 05:37 PM 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 )  :smileyhappy:

 

//-------------------------------------------------------

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

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

*Expert Elite*
753 Posts
54 Kudos
Registered: ‎02-13-2008
Post 6 of 10

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

09-16-2011 09:05 PM in reply to: KerryBrown

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
Valued Contributor
77 Posts
0 Kudos
Registered: ‎07-02-2010
Post 7 of 10

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

09-17-2011 09:35 AM in reply to: KerryBrown

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 )  :smileyhappy:

 

 

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

 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

 

 


 


 

Valued Mentor
278 Posts
22 Kudos
Registered: ‎11-29-2008
Post 8 of 10

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

09-17-2011 03:07 PM 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

*Expert Elite*
753 Posts
54 Kudos
Registered: ‎02-13-2008
Post 9 of 10

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

09-18-2011 12:05 AM in reply to: KerryBrown

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
Valued Mentor
341 Posts
53 Kudos
Registered: ‎05-12-2009
Post 10 of 10

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

09-19-2011 10:03 AM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!