|
POST
|
What I haven't attempted yet but may try is using IQuerySize to get the updated size in points for the legend, convert to page layout units, and assign that as the new geometry for the map surround frame element. That seemed to work. Here's some C# code to handle reassigning the geometry to the element. // Update size of element containing the legend
// av is IActiveView on an instance of the page layout
IQuerySize querySize = mapSurroundFrame.MapSurround as IQuerySize;
Double w = 0;
Double h = 0;
querySize.QuerySize(ref w, ref h);
// Convert from points to page units, e.g., inches
w = av.ScreenDisplay.DisplayTransformation.FromPoints(w);
h = av.ScreenDisplay.DisplayTransformation.FromPoints(h);
IEnvelope envelope = new EnvelopeClass();
// The legend is anchored at x=1 inch, y=2 inch on the layout
envelope.PutCoords(1, 2, (1 + w), (2 + h));
IElement element = mapSurroundFrame as IElement;
element.Geometry = envelope; ---------------------------------------------- For completeness, here are some other things I tried which didn't work: ILegend.Refresh() -- I think that just helps the legend redraw on screen if you changed it programmatically. It didn't fix the geometry. ILegend.QueryBounds -- Unlike on IElement, this QueryBounds method takes an old envelope and a new one. I thought the new one might be the correct geometry. Indeed the is returned from the method with a different size than the old envelope. However, assigning the new envelope as the element's geometry didn't solve the problem.
... View more
06-25-2014
12:15 PM
|
0
|
0
|
2353
|
|
POST
|
You need a concrete Legend object to call fixedAspectRatio. Thanks for the fast response. mapSurroundFrame.MapSurround returns an instance of the Legend coclass, so that should be a concrete object. I've continued digging into this problem and found that when I create a legend manually through the ArcMap GUI, I see that the checkbox for Preserve Aspect Ratio is disabled, so I'm guessing that changing it is not implemented for legends. For more background, I followed the example here: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//00490000006w000000 When instantiated, a legend includes all layers in the map, so I then remove some of them. This changes the size of the legend that you see on screen. However, when you look at the properties for the legend's map surround frame, it still has its original width and height as generated in the code. This makes aligning and distributing the legend element with other elements problematic. Even changing the anchor point through the GUI can result in unwanted resizing. What I haven't attempted yet but may try is using IQuerySize to get the updated size in points for the legend, convert to page layout units, and assign that as the new geometry for the map surround frame element. This would help with manual positioning as long as the legend isn't edited, but after it is edited, I think it will still keep the last size as set by the code instead of responding appropriately to resizing through the GUI. But that seems like a kluge (if it even works) so I'm hoping you or another expert on here knows of a better way.
... View more
06-25-2014
11:31 AM
|
0
|
0
|
2353
|
|
POST
|
I'm creating a legend. I want to set IBoundsProperties.FixedAspectRatio to False. When I run the code, I get "The method or operation is not implemented." Code snippet (C#): ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2;
IBoundsProperties bounds = legend as IBoundsProperties;
bounds.FixedAspectRatio = false; I get the same error if I cast to IBoundsProperties from the mapSurroundFrame object instead of the legend object.
... View more
06-25-2014
08:50 AM
|
0
|
17
|
4929
|
|
POST
|
I've noticed the same thing when I write a description in metadata for a layer and then view the description for that layer in the layer properties dialog in ArcMap. The dialog shows the description from the metadata but includes the HTML tags (<div>, <span>, etc.) even though I didn't specify any tags or use any formatting when I wrote the metadata. I think this is a bug. I think the Description on the layer properties dialog should either parse or ignore HTML tags. Same goes for other places in the ArcGIS family of products where metadata is used for descriptions.
... View more
09-10-2013
08:26 AM
|
0
|
0
|
732
|
|
POST
|
I don't know of an online sample, but this code worked for me in ArcGIS 9.2 VBA. It just sends forward the first map it finds in the layout. Dim d As IMxDocument
Set d = ThisDocument
Dim gc As IGraphicsContainer
Dim gcs As IGraphicsContainerSelect
Set gc = d.PageLayout
Set gcs = gc
gcs.UnselectAllElements
gc.Reset
Dim e As IElement
Set e = gc.Next
Do Until e Is Nothing
If TypeOf e Is IMapFrame Then
gcs.SelectElement e
gc.BringForward g.SelectedElements
Exit Do
End If
Set e = gc.Next
Loop
d.ActiveView.Refresh
... View more
03-06-2012
09:05 AM
|
0
|
0
|
502
|
|
POST
|
Did you try this line? featLayer.getSelectionSet().search(null, false, cursor); If it works, it would be fewer lines of code and might be more efficient since you aren't looping through OIDs to create a whereclause. Your code would become: // Get a cursor on selected features
IFeatureCursor cursor = null;
featLayer.getSelectionSet().search(null, false, cursor);
// Delete all features in the cursor
IFeature feature = null;
while ((feature = cursor.nextFeature()) != null) {
cursor.deleteFeature(); // Or maybe try feature.delete()
}
// Clear the selection set, because deleting this way doesn't notify the table or the TOC to udpate.
featLayer.clear();
// optionally call updateContents on map document
// If the cursor is no longer needed, release it.
Cleaner.release(cursor);
... View more
01-24-2012
05:20 AM
|
0
|
0
|
1872
|
|
POST
|
Try this for a quick fix: Set pStatusBar = ThisDocument.Parent.StatusBar If Application appears in several more places, you could do something like the following, where you basically substitute pApp in place of Application:
Dim pApp As IApplication
Set pApp = ThisDocument.Parent
Set pStatusBar = pApp.StatusBar
... View more
01-23-2012
09:48 AM
|
0
|
0
|
355
|
|
POST
|
Instead of querying for the OIDs, you could iterate directly on the features. Are you working in Java? I don't work in Java, but I think the code would be something like // Get a cursor on selected features
IFeatureCursor cursor = null;
featLayer.getSelectionSet().search(null, false, cursor);
// Delete all features in the cursor
IFeature feature = null;
while ((feature = cursor.nextFeature()) != null) {
cursor.deleteFeature(); // Or maybe try feature.delete()
} As for which is better, you're probably the best judge of that. Generally I find running GP tools to be a little slower than writing my own code to do the same work. However, using GP tools means I let ESRI handle their end of code development and maintenance, which usually makes my life a little easier.
... View more
01-23-2012
09:36 AM
|
0
|
0
|
1872
|
|
POST
|
You should be able to use the ProgID to add the ESRI command or tool. For example, for an ArcGIS 10 add-in, you would edit the toolbar section of Config.esriaddinx to add a Button element mapped to an ESRI tool. To add the Zoom In Tool, you would add <Button refID="esriArcMapUI.ZoomInTool" />, as shown in the example below: <Toolbars>
<Toolbar id="Microsoft_ArcMapAddin1_My_Toolbar" caption="My Toolbar" showInitially="false">
<Items>
<Button refID="Microsoft_ArcMapAddin1_Button1" />
<Button refID="esriArcMapUI.ZoomInTool" />
</Items>
</Toolbar>
</Toolbars>
After you build the solution, the Zoom In Tool should show up on your toolbar in ArcMap. The key is to use the right ProgID. IDs from 9.3 help are listed at http://resources.esri.com/help/9.3/arcgisdesktop/com/shared/desktop/reference/ArcMapIds.htm
... View more
01-23-2012
09:13 AM
|
0
|
0
|
604
|
|
POST
|
There's a GP tool called DeleteRows that should only delete the selected rows. Can you programmatically call that? http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualHelp/engine/index.html#//0001000004q4000000 Or use ISelectionSet.search to get a cursor over which you can iterate and call delete().
... View more
01-20-2012
07:09 AM
|
0
|
0
|
1872
|
|
POST
|
Thanks for the help, Tim. I implemented your suggestions. The routine is still creating features with empty geometries. Any idea why it would add a row to the table but not add take the geometry? The shape field does show 'polygon' but when I select or try to zoom to one onf the new features - nothing. Maybe you need to close the polygon by adding the first point to the end of the point collection. This code worked for me. Dim pMap As IMap = My.ArcMap.Document.FocusMap Dim pFLayer As IFeatureLayer = pMap.Layer(0) Dim pFC As IFeatureClass = pFLayer.FeatureClass Dim pCursor As IFeatureCursor = pFC.Search(Nothing, False) Dim pFeature As IFeature = pCursor.NextFeature Dim pEnv As IEnvelope Dim pPoly As IPointCollection Dim uid As ESRI.ArcGIS.esriSystem.UID uid = New ESRI.ArcGIS.esriSystem.UIDClass() uid.Value = "esriEditor.Editor" Dim editor As IEditor editor = CType(My.ArcMap.Application.FindExtensionByCLSID(uid), IEditor) Dim pDS As IDataset = pFLayer.FeatureClass Dim pWS As IWorkspace = pDS.Workspace 'Check to see if a workspace is already being edited. If editor.EditState = esriEditState.esriStateNotEditing Then editor.StartEditing(pWS) End If Do Until pFeature Is Nothing ' Expand the envelope pEnv = pFeature.Shape.Envelope pEnv.Expand(100, 100, False) ' Create the vertices Dim LL As New Point LL.PutCoords(pEnv.XMin, pEnv.YMin) Dim LR As New Point LR.PutCoords(pEnv.XMax, pEnv.YMin) Dim UR As New Point UR.PutCoords(pEnv.XMax, pEnv.YMax) Dim UL As New Point UL.PutCoords(pEnv.XMin, pEnv.YMax) ' Add vertices to the polygon and close the loop pPoly = New Polygon pPoly.AddPoint(LL) pPoly.AddPoint(LR) pPoly.AddPoint(UR) pPoly.AddPoint(UL) pPoly.AddPoint(LL) ' Assign properties to the new feature Dim pNewFeat As IFeature = pFC.CreateFeature pNewFeat.Shape = pPoly pNewFeat.Value(3) = pFeature.Value(3) pNewFeat.Store() pFeature = pCursor.NextFeature Loop editor.StopEditing(True) My.ArcMap.Document.ActiveView.Refresh() By the way, consider using a ComReleaser to manage the lifetime of your cursor. http://blogs.esri.com/dev/blogs/geodatabase/archive/2008/12/18/using-the-comreleaser-to-manage-the-lifetime-of-cursors-in-.net.aspx If you are processing many features, consider using an insert cursor to improve performance. http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/00010000049v000000.htm
... View more
01-19-2012
12:06 PM
|
0
|
0
|
2970
|
|
POST
|
If you are just adding a buffer to the existing polygon then you can use the below code. You may have to convert it to VB though.
ITopologicalOperator topologicalOperator = pFeature.Shape as ITopologicalOperator;
IPolygon pPoly = topologicalOperator.Buffer(100) as IPolygon;
pNewFeat.Shape = pPoly;
Is there a way to force the topo op to preserve the square corners of the rectangles?
... View more
01-19-2012
12:01 PM
|
0
|
0
|
2970
|
|
POST
|
Also, I recommend creating a new envelope for each iteration of the loop. Otherwise, the envelope coordinates might do funny things if the new XMax+100 is less than the previous XMin. A more concise way to write it might be (inside the loop): pEnv = pFeature.Shape.Envelope
pEnv.Expand(100, 100, False) This copies the current feature's envelope and expands it in the x and y directions by 100. Then you don't need the four lines of code like pEnv.XMax = pFeature.Shape.Envelope.XMax + 100.
... View more
01-19-2012
09:47 AM
|
0
|
0
|
2970
|
|
POST
|
A few changes to the code might do the trick. Try dimming pPoly as IPointCollection instead of New Polygon. Dim pPoly As IPointCollection Then, in your loop, create a new polygon and add each corner point to it. pPoly = New Polygon
Dim LL As New Point
LL.PutCoords(pEnv.XMin, pEnv.YMin)
pPoly.AddPoint(LL)
Dim LR As New Point
LR.PutCoords(pEnv.XMax, pEnv.YMin)
pPoly.AddPoint(LR) ...and so on.
... View more
01-19-2012
09:27 AM
|
0
|
0
|
2970
|
|
POST
|
If you want to use a config XML, I recommend adding your own rather than using the Config.esriaddinx file. This keeps things clean. To add your own file in Visual Studio 2010: In Solution Explorer, right-click your add-in, point to Add, and click New Item. With the Common Items category selected, choose XML File. Give it a name and click Add. Click the XML file in the Solution Explorer, and then in the Properties window, set Copy to Output Directory to "Copy always." You should now be able to use the GetAppPath code that was previously posted along with IO.Path.Combine to create the path to the XML file. For more on adding your own files for use with add-ins, see http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Advanced_add_in_concepts/0001000004n7000000/ The article says, "You can create additional folders and files under the Install folder. This is useful in cases where you want to ship data as part of your add-in. If you're adding data through your Visual Studio project, set the Copy to Output Directory property to the Copy always setting..."
... View more
01-12-2012
11:51 AM
|
0
|
0
|
2582
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-11-2020 11:56 AM | |
| 4 | 06-03-2021 09:16 AM | |
| 2 | 12-13-2020 12:16 PM | |
| 1 | 12-02-2020 12:11 PM | |
| 1 | 06-05-2019 06:55 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-05-2024
06:00 PM
|