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
Solved! Go to Solution.
Solved by chiefbraincloud. Go to Solution.
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
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.
@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 in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
class keyThumper<T> : Lazy<T>; another Swamper
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)
@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
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 in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
class keyThumper<T> : Lazy<T>; another Swamper
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
I will stop here before I say something to get me kicked off.
Edited by
Discussion_Admin
Can't find what you're looking for? Ask the community or share your knowledge.