.NET

Reply
Valued Contributor
CommCorp
Posts: 98
Registered: ‎03-19-2007
Message 1 of 5 (222 Views)
Accepted Solution

Need help adding a layoutgrid2d to drawing please

222 Views, 4 Replies
02-04-2014 07:32 AM

I am adding a "Layoutgrid2d" to my drawing via VB.Net just fine but Im having a problem getting the grid to be my specified size.

If I inspect the layoutgrid object just before I appendentity the  Basegrid values for UAxisLength, USpacing, VAxisLength and VSpacing are my specified values but as soon as I appendentitiy the UAxisLength and VAxisLength values are reset back to a default value while USpacing and VSpacing remian at my values.

When the layoutgrid appears in the drawing it is sized at the incorrect, default values.

 

I have even tried to alter these values AFTER I have added the layoutgrid and I still cannot set the UAxisLength and VAxisLength values.

 

Can someone tell me what im doing wrong?

 

Using Gridtrans As Transaction = db.TransactionManager.StartTransaction()

  ' draw the 2d layoutgrid
  Dim bt As BlockTable = Gridtrans.GetObject(db.BlockTableId, OpenMode.ForRead)
  Dim btr As BlockTableRecord = Gridtrans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

  Dim log2d As New AecDBS.LayoutGrid2d
  log2d.SetDatabaseDefaults()
  log2d.SetToStandard(db)

  log2d.Location = pt1
  log2d.Rotation = wrot

  log2d.BaseGrid.ULayoutMode = 0
  log2d.BaseGrid.UAxisLength = 42.0 'This wont stay set!
  log2d.BaseGrid.USpacing = 42.0 'Stays set

  log2d.BaseGrid.VLayoutMode = 0
  log2d.BaseGrid.VAxisLength = 0.5 ' This wont stay set!
  log2d.BaseGrid.VSpacing = 0.5 'Stays set

  id = btr.AppendEntity(log2d)
  Gridtrans.AddNewlyCreatedDBObject(log2d, True)
  Gridtrans.Commit()
End Using

 

 

Dear John,

Thank you for your patience.

I heard back from the development team.

Here is there explanation:

Answer A:

May you verify if the following testing code will work for the case? It’s from our existing test code. It looks like the customer missed calling the methods grid2d.GridType, grid2d.BaseGrid.ULayoutMode and grid2d.BaseGrid.UpdateParameters.

 grid2d = new LayoutGrid2d();
grid2d.SetToStandard(db);
grid2d.SetDatabaseDefaults(db);
grid2d.GridType = Autodesk.Aec.DatabaseServices.GridType.UVRectangular;
grid2d.BaseGrid.UAxisLength = 40;
grid2d.BaseGrid.ULayoutMode = UVLayoutModeType.SpaceEvenly;
grid2d.BaseGrid.UStartOffset = 0;
grid2d.BaseGrid.AppendGridRow(0);
grid2d.BaseGrid.AppendGridRow(1);
grid2d.BaseGrid.AppendGridRow(2);
grid2d.BaseGrid.AppendGridRow(3);
grid2d.BaseGrid.UEndOffset = 0;
grid2d.BaseGrid.VAxisLength = 30;
grid2d.BaseGrid.VLayoutMode = UVLayoutModeType.SpaceEvenly;
grid2d.BaseGrid.VStartOffset = 0;
grid2d.BaseGrid.VEndOffset = 0;
grid2d.BaseGrid.AppendGridColumn(0);
grid2d.BaseGrid.AppendGridColumn(1);
grid2d.BaseGrid.AppendGridColumn(2);
grid2d.BaseGrid.UpdateParameters();

 


 
Answer B:

The answer depends on what the developer wants to do. The original code
 

 log2d.BaseGrid.ULayoutMode = 0
log2d.BaseGrid.UAxisLength = 42.0 'This wont stay set!
log2d.BaseGrid.USpacing = 42.0 'Stays set
log2d.BaseGrid.VLayoutMode = 0
log2d.BaseGrid.VAxisLength = 0.5 ' This wont stay set!
log2d.BaseGrid.VSpacing = 0.5 'Stays set

 


 
seems to be trying to create a grid with one column one row, in the size of 42.0 * 0.5.
 
As the grid already has one column and one row by default at creation, the easiest way is adjusting the size of existing column and row. Here's the code:
 

 log2d.BaseGrid.ULayoutMode = 0
log2d.BaseGrid.MoveGridColumn(log2d.BaseGrid.UAxisLength, 42.0)
log2d.BaseGrid.VLayoutMode = 0
log2d.BaseGrid.MoveGridRow(log2d.BaseGrid.VAxisLength, 0.5)

 


 
You could still set U/VAxisLength values, but there won't be any visual differences.
 
The problem of the original code is that it's using manual layout mode, ULayoutMode = UVLayoutModeType.Manual (or 0 as in the code). In this mode, the underlying logic always increases the axis length to match the maximum column/row position. The default column size is 350 at creation, so the specified UAxisLength 42.0 will always get rejected without resizing the column.

Probably some samples could help more...
 
1. Repeat mode: specify overall size, and spacing.
 
The following code creates a grid with 5 columns and 2 rows.
 

 log2d.BaseGrid.ULayoutMode = UVLayoutModeType.Repeat;
log2d.BaseGrid.UAxisLength = 100;
log2d.BaseGrid.USpacing = 20;
log2d.BaseGrid.VLayoutMode = UVLayoutModeType.Repeat;
log2d.BaseGrid.VAxisLength = 50;
log2d.BaseGrid.VSpacing = 25;

 



2. Space evenly mode: specify overall size, and then specify the number of columns/rows via appending.
 
The following code creates a grid with 6 columns and 2 rows. Please note that, the specified column/row position is not important, the actual position will be calculated automatically from the overall size and the number of columns/rows.
 
The code looks a bit weird. Anyway, this is how it works for now.
 

 log2d.BaseGrid.ULayoutMode = UVLayoutModeType.SpaceEvenly;
log2d.BaseGrid.UAxisLength = 100;
for (int i = 1; i <= 5; i++)
log2d.BaseGrid.AppendGridColumn(i);
log2d.BaseGrid.VLayoutMode = UVLayoutModeType.SpaceEvenly;
log2d.BaseGrid.VAxisLength = 50;
log2d.BaseGrid.AppendGridRow(log2d.BaseGrid.VAxisLength / 2);

 



3. Manual mode: specify each column and row manually.
 
The following code creates a more complex grid.
 

 log2d.BaseGrid.ULayoutMode = UVLayoutModeType.Manual;
log2d.BaseGrid.MoveGridColumn(log2d.BaseGrid.UAxisLength, 10);
log2d.BaseGrid.AppendGridColumn(20);
log2d.BaseGrid.AppendGridColumn(50);
log2d.BaseGrid.AppendGridColumn(98);
log2d.BaseGrid.AppendGridColumn(100);
log2d.BaseGrid.VLayoutMode = UVLayoutModeType.Manual;
log2d.BaseGrid.MoveGridRow(log2d.BaseGrid.VAxisLength, 30);
log2d.BaseGrid.AppendGridRow(50);

 



tony_samples.png

I hope this helps.

Best regards,

 

Jeremy

ADN Support Specialist
jeremytammik
Posts: 563
Registered: ‎08-20-2007
Message 2 of 5 (192 Views)

Re: Need help adding a layoutgrid2d to drawing please

02-05-2014 11:21 PM in reply to: CommCorp

Dear John,

Thank you for your query.

That looks strange.

Have you tried varying the sequence of property settings?

E..g., setting the length first and the spacing afterwards?

Have you tried creating the grid object first, in one transaction, and then setting the properties later, in another, separate, transaction?

If nothing else helps, I would suggest that you provide a complete little reproducible case for us to pass on to the development team for further exploration, i.e.

  • A complete yet minimal sample model to run a test in.
  • A complete yet minimal Visual Studio .NET add-in solution so that we can immediately compile, load and run the application and explore its behaviour live in the sample model you provide.
  • Detailed step-by-step instructions for reproducing the issue.
  • Specification of the exact behaviour you observe versus what you expect.


Is that possible?

Thank you!

Best regards,



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Valued Contributor
CommCorp
Posts: 98
Registered: ‎03-19-2007
Message 3 of 5 (181 Views)

Re: Need help adding a layoutgrid2d to drawing please

02-06-2014 04:24 AM in reply to: jeremytammik

Attached is a stripped down project.

 

I have tried varing the sequence and it made no difference.

 

I have also tried adding the object to the db first in one transaction then editing later in another and that did not work either.

 

The attached sample should create a single cell layoutgrid2d 48" x 48" but no matter what i do it creates a 350" x 500" grid.

 

The code does set and keep the "ULayoutMode" and "VLayoutMode" properties. 

 

ADN Support Specialist
jeremytammik
Posts: 563
Registered: ‎08-20-2007
Message 4 of 5 (178 Views)

Re: Need help adding a layoutgrid2d to drawing please

02-06-2014 04:51 AM in reply to: CommCorp

Dear John,

Thank you for your research and sample material.

I passed it on to the development team for further exploration.

I'll let you know as soon as I hear anything back from them.

I hope this helps.

Best regards,

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

ADN Support Specialist
jeremytammik
Posts: 563
Registered: ‎08-20-2007
Message 5 of 5 (154 Views)

Re: Need help adding a layoutgrid2d to drawing please

02-10-2014 12:06 AM in reply to: jeremytammik

Dear John,

Thank you for your patience.

I heard back from the development team.

Here is there explanation:

Answer A:

May you verify if the following testing code will work for the case? It’s from our existing test code. It looks like the customer missed calling the methods grid2d.GridType, grid2d.BaseGrid.ULayoutMode and grid2d.BaseGrid.UpdateParameters.

  grid2d = new LayoutGrid2d();
  grid2d.SetToStandard(db);
  grid2d.SetDatabaseDefaults(db);
  grid2d.GridType = Autodesk.Aec.DatabaseServices.GridType.UVRectangular;
  grid2d.BaseGrid.UAxisLength = 40;
  grid2d.BaseGrid.ULayoutMode = UVLayoutModeType.SpaceEvenly;
  grid2d.BaseGrid.UStartOffset = 0;
  grid2d.BaseGrid.AppendGridRow(0);
  grid2d.BaseGrid.AppendGridRow(1);
  grid2d.BaseGrid.AppendGridRow(2);
  grid2d.BaseGrid.AppendGridRow(3);
  grid2d.BaseGrid.UEndOffset = 0;
  grid2d.BaseGrid.VAxisLength = 30;
  grid2d.BaseGrid.VLayoutMode = UVLayoutModeType.SpaceEvenly;
  grid2d.BaseGrid.VStartOffset = 0;
  grid2d.BaseGrid.VEndOffset = 0;
  grid2d.BaseGrid.AppendGridColumn(0);
  grid2d.BaseGrid.AppendGridColumn(1);
  grid2d.BaseGrid.AppendGridColumn(2);
  grid2d.BaseGrid.UpdateParameters();

 


 
Answer B:

The answer depends on what the developer wants to do. The original code
 

  log2d.BaseGrid.ULayoutMode = 0
  log2d.BaseGrid.UAxisLength = 42.0 'This wont stay set!
  log2d.BaseGrid.USpacing = 42.0 'Stays set

  log2d.BaseGrid.VLayoutMode = 0
  log2d.BaseGrid.VAxisLength = 0.5 ' This wont stay set!
  log2d.BaseGrid.VSpacing = 0.5 'Stays set

 


 
seems to be trying to create a grid with one column one row, in the size of 42.0 * 0.5.
 
As the grid already has one column and one row by default at creation, the easiest way is adjusting the size of existing column and row. Here's the code:
 

  log2d.BaseGrid.ULayoutMode = 0
  log2d.BaseGrid.MoveGridColumn(log2d.BaseGrid.UAxisLength, 42.0)
  log2d.BaseGrid.VLayoutMode = 0
  log2d.BaseGrid.MoveGridRow(log2d.BaseGrid.VAxisLength, 0.5)

 


 
You could still set U/VAxisLength values, but there won't be any visual differences.
 
The problem of the original code is that it's using manual layout mode, ULayoutMode = UVLayoutModeType.Manual (or 0 as in the code). In this mode, the underlying logic always increases the axis length to match the maximum column/row position. The default column size is 350 at creation, so the specified UAxisLength 42.0 will always get rejected without resizing the column.

Probably some samples could help more...
 
1. Repeat mode: specify overall size, and spacing.
 
The following code creates a grid with 5 columns and 2 rows.
 

  log2d.BaseGrid.ULayoutMode = UVLayoutModeType.Repeat;
  log2d.BaseGrid.UAxisLength = 100;
  log2d.BaseGrid.USpacing = 20;
  log2d.BaseGrid.VLayoutMode = UVLayoutModeType.Repeat;
  log2d.BaseGrid.VAxisLength = 50;
  log2d.BaseGrid.VSpacing = 25;

 



2. Space evenly mode: specify overall size, and then specify the number of columns/rows via appending.
 
The following code creates a grid with 6 columns and 2 rows. Please note that, the specified column/row position is not important, the actual position will be calculated automatically from the overall size and the number of columns/rows.
 
The code looks a bit weird. Anyway, this is how it works for now.
 

  log2d.BaseGrid.ULayoutMode = UVLayoutModeType.SpaceEvenly;
  log2d.BaseGrid.UAxisLength = 100;
  for (int i = 1; i <= 5; i++)
    log2d.BaseGrid.AppendGridColumn(i);
  log2d.BaseGrid.VLayoutMode = UVLayoutModeType.SpaceEvenly;
  log2d.BaseGrid.VAxisLength = 50;
  log2d.BaseGrid.AppendGridRow(log2d.BaseGrid.VAxisLength / 2);

 



3. Manual mode: specify each column and row manually.
 
The following code creates a more complex grid.
 

  log2d.BaseGrid.ULayoutMode = UVLayoutModeType.Manual;
  log2d.BaseGrid.MoveGridColumn(log2d.BaseGrid.UAxisLength, 10);
  log2d.BaseGrid.AppendGridColumn(20);
  log2d.BaseGrid.AppendGridColumn(50);
  log2d.BaseGrid.AppendGridColumn(98);
  log2d.BaseGrid.AppendGridColumn(100);
  log2d.BaseGrid.VLayoutMode = UVLayoutModeType.Manual;
  log2d.BaseGrid.MoveGridRow(log2d.BaseGrid.VAxisLength, 30);
  log2d.BaseGrid.AppendGridRow(50);

 



tony_samples.png

I hope this helps.

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.