askrius Posted January 20, 2009 Posted January 20, 2009 Does anyone know what the 'Password' value should be? With C# there are no overrides for the last value, and I get a hideous error when I try to use any object I can think of...even the value if IAcadSecurityParams.Password.... Assistance? Quote
SEANT Posted January 20, 2009 Posted January 20, 2009 If you’re using: Database.ReadDwgFile Method (string, FileShare, [MarshalAs(UnmanagedType.U1)] bool, string) and there is no associated password then you should be able to just pass in an empty string. For example: . . . . . Database dbIns = new Database(false, false); try { // Read the 'strPath' file into the new database. dbIns.ReadDwgFile(strPath, System.IO.FileShare.Read, true, ""); // Try to insert our the dwg file as a block and get the return id of // the new block table record. BlockID = db.Insert(blockName, dbIns, true); } catch { BlockID = ObjectId.Null; } . . . . . Quote
askrius Posted January 20, 2009 Author Posted January 20, 2009 If you’re using: Database.ReadDwgFile Method (string, FileShare, [MarshalAs(UnmanagedType.U1)] bool, string) and there is no associated password then you should be able to just pass in an empty string. For example: . . . . . Database dbIns = new Database(false, false); try { // Read the 'strPath' file into the new database. dbIns.ReadDwgFile(strPath, System.IO.FileShare.Read, true, ""); // Try to insert our the dwg file as a block and get the return id of // the new block table record. BlockID = db.Insert(blockName, dbIns, true); } catch { BlockID = ObjectId.Null; } . . . . . Interesting. I have tried passsing an empty string to it; no luck. I get Unhandled Exception: System.Runtime.InteropServices.COMException (0x8000FFFF): C atastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) at AXDBLib.AcadModelSpaceClass.InsertBlock(Object InsertionPoint, String Name , Double Xscale, Double Yscale, Double Zscale, Double Rotation, Object Password) at asapDWGEngine.asapHost.test() in C:\asapDWGEngine\asapDWGEngine\asapHost.c s:line 60 at asapDWGEngine.Program.Main(String[] args) in C:\asapDWGEngine\asapDWGEngin e\Program.cs:line 26 There is no password on the DWG...hrm... I load the drawing with a call via db.ReadDwgFile(), set the working database to the loaded DWG...set an AcadDatabase object to the db (typecast) as per some examples I have seen...and no luck. I can do other operations just like I would via COM without a problem...but for some reason this doesnt work... Quote
SEANT Posted January 21, 2009 Posted January 21, 2009 Regarding that call in a strictly managed code environment, null is also acceptable as a replacement for “”. I couldn’t tell you why the code it is not working based on that exception. Is using the COM interop essential? Is the X, Y, and Zscale critical? If so, Could you use the: Database.Insert Method (Matrix3d, Database, [MarshalAs(UnmanagedType.U1)] bool) overload with the appropriate matrix set to scale? Quote
askrius Posted January 21, 2009 Author Posted January 21, 2009 Ooooook. So, when I use database.insert(), with 'database' being the database of the drawing in which i would like the blocks to be inserted said blocks are being placed in Paperspace table, not modelspace? Now I could have sworn that the documentation stated that 'insert()' placed the source blockrecord in the database's modelspace block record.... Quote
askrius Posted January 21, 2009 Author Posted January 21, 2009 Ooooook. So, when I use database.insert(), with 'database' being the database of the drawing in which i would like the blocks to be inserted said blocks are being placed in Paperspace table, not modelspace? Now I could have sworn that the documentation stated that 'insert()' placed the source blockrecord in the database's modelspace block record.... oops, i edited instead of replied! In addition to the issue above I have noticed the following: When the blocks are inserted visible attributes (text) are not correctly aligned...unless its DXF as the output! The DXF everything shows correctly...the DWG...its all off. In the case of dynamic blocks the attributes will realign correctly if the visiblity state is toggled, even if the current (default) state is chosen.... Quote
SEANT Posted January 22, 2009 Posted January 22, 2009 Ooooook. So, when I use database.insert(), with 'database' being the database of the drawing in which i would like the blocks to be inserted said blocks are being placed in Paperspace table, not modelspace? Now I could have sworn that the documentation stated that 'insert()' placed the source blockrecord in the database's modelspace block record.... I have to agree that the wording used by the help docs is often misleading. The db.Insert method adds the incoming data to the Block Table as a new BlockTableRecord. That particular Block can then be inserted as a BlockReference into the any other BlockTableRecord. If something is set up like so: . . . . . BlockTableRecord currSpace = tr.GetObject( db.CurrentSpaceId, OpenMode.ForWrite ) as BlockTableRecord; BlockReference bref = new BlockReference( ppr.Value, id ); currSpace.AppendEntity( bref ); . . . . . Then the BlockReference will appear in whichever space is current. oops, i edited instead of replied! In addition to the issue above I have noticed the following: When the blocks are inserted visible attributes (text) are not correctly aligned...unless its DXF as the output! The DXF everything shows correctly...the DWG...its all off. In the case of dynamic blocks the attributes will realign correctly if the visiblity state is toggled, even if the current (default) state is chosen.... See if this thread has any bearing on that situation. http://www.cadtutor.net/forum/showthread.php?t=28819 Quote
askrius Posted January 22, 2009 Author Posted January 22, 2009 I have to agree that the wording used by the help docs is often misleading. The db.Insert method adds the incoming data to the Block Table as a new BlockTableRecord. That particular Block can then be inserted as a BlockReference into the any other BlockTableRecord. If something is set up like so: . . . . . BlockTableRecord currSpace = tr.GetObject( db.CurrentSpaceId, OpenMode.ForWrite ) as BlockTableRecord; BlockReference bref = new BlockReference( ppr.Value, id ); currSpace.AppendEntity( bref ); . . . . . Then the BlockReference will appear in whichever space is current. See if this thread has any bearing on that situation. http://www.cadtutor.net/forum/showthread.php?t=28819 Thanks for the reply. I fixed my mistake with the modelspace issue lastnight. I had my database's crossed! As for the second issue: I have sucessfully inserted the block and pasted the attribute references...it seems odd to me that the DXF output would display the visible attributes in the correct location while the DWG output would not (they apear at the block's insertionpoint)... Quote
askrius Posted January 23, 2009 Author Posted January 23, 2009 Shared Sub ApplyAttributeDef(ByRef BlockReference As Autodesk.AutoCAD.DatabaseServices.BlockReference) Dim Block As BlockTableRecord = BlockReference.BlockTableRecord.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead) If Not Block.HasAttributeDefinitions Then Exit Sub If Block.Database Is Nothing Then Exit Sub Dim Trans As Transaction = Block.Database.TransactionManager.StartTransaction Try If BlockReference.Database Is Nothing Then Block.Database.AddDBObject(BlockReference) For Each Id As ObjectId In Block Dim Ent As Entity = Id.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead) If TypeOf Ent Is AttributeDefinition Then Dim AttDef As AttributeDefinition = Ent Dim AttRef As New AttributeReference BlockReference.AttributeCollection.AppendAttribute(AttRef) AttRef.SetPropertiesFrom(AttDef) AttRef.SetAttributeFromBlock(AttDef, BlockReference.BlockTransform) Trans.AddNewlyCreatedDBObject(AttRef, True) End If Next Trans.Commit() Catch ex As Autodesk.AutoCAD.Runtime.Exception Trans.Abort() Finally Trans.Dispose() End Try End Sub The above sub is how I am applying the attribute defs, the result I am getting (again, only in DWG output, not in DXF output) is attached. As you see the visible attribute (text, the number '1' in this case) is does appear...however, it should be centered within the block (rect w/circle inscribed in it). when the blockref is doubleclicked in in the drawing by a user and the value changed (or even left the same), the attribute will 'move' to the correct location! I'm stumped! Quote
SEANT Posted January 23, 2009 Posted January 23, 2009 Hmm, the only thing I can tell you is that I plugged your sub into a setup here, and everything updated as it should. Perhaps look at the calling routine, does it apply any subsequent adjustments to the BlockReference that would modify its transformation matrix? Quote
askrius Posted January 23, 2009 Author Posted January 23, 2009 Hmm, the only thing I can tell you is that I plugged your sub into a setup here, and everything updated as it should. Perhaps look at the calling routine, does it apply any subsequent adjustments to the BlockReference that would modify its transformation matrix? Ooooook.... thanks for the assistance. I redefined those attributes in the source block(s) and all works as required now. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.