Jump to content

Recommended Posts

Posted

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?

Posted

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;
} 

. . . . . 

Posted
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...

Posted

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?

Posted

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....

Posted
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....

Posted
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

Posted
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)...

Posted

       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!

ss_1.jpg

Posted

Hmm, the only thing I can tell you is that I plugged your sub into a setup here, and everything updated as it should. :huh:

 

Perhaps look at the calling routine, does it apply any subsequent adjustments to the BlockReference that would modify its transformation matrix?

Posted
Hmm, the only thing I can tell you is that I plugged your sub into a setup here, and everything updated as it should. :huh:

 

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...