Author Topic: Solved - eInvalidInput in AttributeReference.SetAttributeFromBlock() in BricsCAD  (Read 335 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Water Moccasin
  • Posts: 2239
  • Marko Ribar, architect
Re: eInvalidInput in AttributeReference.SetAttributeFromBlock() in BricsCAD
« Reply #15 on: February 14, 2020, 08:37:23 AM »
Do you know that after adding ATTRIBUTE to BLOCK, so called INSERT entity gets permanently "corrupted" - DXF flag (66 . 1) is added and then if you want to restore BLOCK as it was without attributes, it's impossible to remove flag (66 . 1) even if all attributes removed from block definition... I find this in LISP cumbersome, so perhaps if you operate in NET, you could investigate and this operation...
Relevant AutoLisp topic here :
http://www.theswamp.org/index.php?topic=55172.msg594767#msg594767
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Bernd

  • Newt
  • Posts: 27
Re: eInvalidInput in AttributeReference.SetAttributeFromBlock() in BricsCAD
« Reply #16 on: February 17, 2020, 03:34:54 AM »
Do you have a sample VS Solution?
A sample solution can be downloaded here: https://my.hidrive.com/lnk/R0hpj1zF - attached!
What puzzles me is that the block reference gets inserted even though - in my understanding - the transaction is not being committed (because of the exception - is there an exception? I'm confused).
But one still cannot insert the block afterwards - see my answer to @n.yuan
« Last Edit: February 17, 2020, 05:17:55 AM by Bernd »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6979
  • AKA Daniel
Re: eInvalidInput in AttributeReference.SetAttributeFromBlock() in BricsCAD
« Reply #17 on: February 17, 2020, 05:31:36 AM »
a start, attributeDefinition.Height that is zero, makes teigha sad

Code: [Select]
if (attributeDefinition.Height == 0)
     attributeDefinition.Height = 1;
attributeReference .SetDatabaseDefaults();

Bernd

  • Newt
  • Posts: 27
Re: eInvalidInput in AttributeReference.SetAttributeFromBlock() in BricsCAD
« Reply #18 on: February 17, 2020, 06:40:27 AM »
 :smitten: Feel virtually kissed! That's it.

FYI, Teigha is a bit unforgiving, Itís a great habit to use set database defaults immediately after creating a DB object, or add it to the database
I'm afraid, this is exactly what you pointed out several answers ago  :oops:

Nevertheless - thanks a lot for your patience and to the others trying to help!

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6979
  • AKA Daniel
I only added the attributeReference .SetDatabaseDefaults();, so you knew where to put the lines above it   :laugh:

n.yuan

  • Bull Frog
  • Posts: 282
I previously suspected:

<QUOTE>
The point here is that could be the attributeDefinition added in this way is not properly initialized due to how BricsCAD implement its .NET API
</QUOTE>

It looks like it has been proved: it is BricsCAD's .NET API implementation bug: AttributeDefinition has 0 height if not explicitly set.

I tried this with AutoCAD:

1. Create a TextStyle with its Text Height=0.0, and set this TextStyle as current (so, if Text/Attribute Def/Ref is created and its text style is not specified, this text Style would be used).

2. If manually create text/attribute definition in AutoCAD, and this Text Style is used, AutoCAD always gives a default text height of 0.2, and one cannot set the height to 0.0.

3, Following code adds attribute definition to an existing block (the same as the OP) without setting any property (so, the attribute definition would use current text style):

Code: [Select]
       private static ObjectId UpdateBlockDefinition(Document dwg)
        {
            var blkId = ObjectId.Null;
            var blkName = "TestBlock";

            using (var tran=dwg.TransactionManager.StartTransaction())
            {
                var bt = (BlockTable)tran.GetObject(dwg.Database.BlockTableId, OpenMode.ForRead);
                if (bt.Has(blkName))
                {
                    blkId = bt[blkName];

                    var blk = (BlockTableRecord)tran.GetObject(blkId, OpenMode.ForWrite);
                    var att = new AttributeDefinition();
                    att.Tag = "TAG A";
                    [color=blue]// att = 0.0 //When I explicitly try to set height to 0.0, AutoCAD raises exception[/color]
                    [color=red]blk.AppendEntity(att);[/color]
                    tran.AddNewlyCreatedDBObject(att, true);
                }

                tran.Commit();
            }

            return blkId;
        }

When I examine the varaiable "att" in debugging when a break point is placed in the red line, I can see AutoCAD set its height to 0.2 in spite the TextStyle applied to it has text height being 0.0 and the code does not explicitly set the attribute definition's height. Also, the blue line of code indicates that attribute definition height cannot be 0.0.

So, that is why the OP's code works in AutoCAD.

Since the same code does not work in BriscCAD, one could do the same debugging to examine if BricsCAD somehow makes/allows 0.0 height attribute definition being added into block definition. If so, that is BricsCAD's bug.