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
Solved! Go to Solution.
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.
Is that possible?
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.
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.
Thank you for your patience.
I heard back from the development team.
Here is there explanation:
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.UVRectangul
ar; 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();
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.UAxis
Length, 42.0) log2d.BaseGrid.VLayoutMode = 0 log2d.BaseGrid.MoveGridRow(log2d.BaseGrid.VAxisLen gth, 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.VAxisL
ength / 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.UAxis
Length, 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.VAxisLen gth, 30); log2d.BaseGrid.AppendGridRow(50);
I hope this helps.