How to use datagraphwindow of arcgis programmatically - arcgis

I have been trying to plot a map on axmapcontrol and use the same ITable to create a scatterplot graph in IDataGraphwindow2. Unfortunately the graph appears with correct data but no click events on the graph are working. The left click shows a memory error and the right click shows a disabled menu. For left click I think DataGraphTUI.dll is responsible. When we load the IDataGraphWindow2, we don’t initialize this due to which probably it gives an error.
Please find the code below.
IDataGraphWindow2 pDGWin;
IDataGraphT dataGraphT = new DataGraphTClass();
IWorkspace shapefileWorkspace = null;
IWorkspaceFactory shapefileWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
shapefileWorkspace = shapefileWorkspaceFactory.OpenFromFile("C:\\abc.shp "), 0);
featureWorkspace = (IFeatureWorkspace)shapefileWorkspace;
featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension("c:\\abc.shp"));
ITable gobjJoinedTable = (ITable)featureLayer.FeatureClass;
LoadaxMap(); /// a method to load up the axmapcontrol
dataGraphT.UseSelectedSet = true;
dataGraphT.HighlightSelection = true;
dataGraphT.GeneralProperties.Title = "Scatter Graph";
dataGraphT.LegendProperties.Visible = false;
dataGraphT.get_AxisProperties(0).Title = "Y Axis";
dataGraphT.get_AxisProperties(0).Logarithmic = false;
dataGraphT.get_AxisProperties(2).Title = "X Axis";
dataGraphT.get_AxisProperties(2).Logarithmic = false;
ISeriesProperties seriesProps = dataGraphT.AddSeries("scatter_plot");
seriesProps.SourceData = axMap.get_Layer(0) as ITable; // axMap is the map control. Itable direct binding also works here
seriesProps.SetField(0, "abc.shp-fieldname"); // you may add any fieldname
seriesProps.SetField(1, "abc.shp-fieldname");
dataGraphT.Update(null);
dataGraphT.UseSelectedSet = true;
dataGraphT.HighlightSelection = false;
dataGraphT.Update(null);
pDGWin = new DataGraphWindowClass();
pDGWin.DataGraphBase = dataGraphT;
pDGWin.PutPosition(546, 155, 1040, 540);
pDGWin.Show(true);
The memory error is
Access violation at address 0F4E358B in module 'DatagraphTUI.dll'. Read of addess 00000000

Had the same problem while displaying the graph.
Fixed it by using this line of code:
graphWindow.Application = ArcMap.Application
All it needs is a reference to the ArcMap Application.

Related

Revit: Cannot create dimensions when ViewSection is rotated

I'm trying to set dimension to the elements in a AssemblyInstance. The code operates with coordinates from the first element.
AssemblyInstance ass; //is found and is not null
ViewSection vsec = RevitAuxilaries.CreateAssemblyViewSection(uiapp, ass,
AssemblyDetailViewOrientation.ElevationFront, ElementId.InvalidElementId, 25);
//UIApplication,
AssemblyInstance, AssemblyDetailViewOrientation, TemplateId, scale // created
BoundingBoxXYZ bbox1 = ass.get_BoundingBox(uiapp.ActiveUIDocument.ActiveView);
XYZ ptmid = (bbox1.Max + bbox1.Min) * 0.5;
Element cropboxelm = RevitAuxilaries.GetViewCropBox(uiapp, vsec); //finds CropBox element,
//found
BoundingBoxXYZ bcropbox = vsec.CropBox;
XYZ center = new XYZ(ptmid.X, ptmid.Y, 0.5 * (bcropbox.Max.Z + bcropbox.Min.Z));
Line axis = Line.CreateBound(center, center + XYZ.BasisZ);
RevitAuxilaries.RotateElement2(uiapp, cropboxelm, axis, 0.6981); // UIApplication,, Element,
Line, angle// created
double dw = RevitAuxilaries.GetDimensionFromElement(uiapp, fi, Dimensions.enWidth); //found dw
// = 3.937
ptleft = new XYZ(31.501, -23.3878, 32.4803);
ptrght = new XYZ(31.501 + dw * Math.Cos(0.6981), -23.3878 + dw * Math.Sin(0.6981), 32.4803);
Line ln = RevitAuxilaries.CreateLineFromPoints(uiapp, ptleft, ptrght); //created
ReferenceArray refarr = new ReferenceArray();
refarr.Append(ln.GetEndPointReference(0));
refarr.Append(ln.GetEndPointReference(1));
Dimension dim = null;
using (Transaction trans = new Transaction(uiapp.ActiveUIDocument.Document, "CreADim"))
{
trans.Start();
dim = uiapp.ActiveUIDocument.Document.Create.NewDimension(viewsec, line, refarr);
if (!issame)
{
try
{ dim.ValueOverride = Convert.ToInt32(UnitUtils.Convert(dim.Value.Value,
UnitTypeId.Feet, UnitTypeId.Millimeters)).ToString(); }
catch { }
}
trans.Commit();
uiapp.ActiveUIDocument.RefreshActiveView();
}
ERROR: The direction of dimension is invalid
Error in function checkDir, line 939
What is here wrong?
Have you tried to create the exact same dimension in the exact same context manually through the end user interface? Does that complete as expected? If not, what error message does that generate? If yes, you can analyse the resulting model, its elements and their properties using RevitLookup and possibly discover some required settings that can be added to your API approach.

Photoshop script to duplicate and rename layer

While creating a script that would automate all the different tasks I do when I start working on a new picture on Photoshop, I encountered the following problem.
I want to create different groups and different layers inside these groups. Everything goes perfectly fine until this :
#target photoshop
app.bringToFront();
var doc = app.activeDocument;
newCurve();
var clippingHelpLayerLight = doc.activeLayer;
clippingHelpLayerLight.blendMode = BlendMode.SCREEN;
clippingHelpLayerLight.name = "Clipping Help Layer - Light";
clippingHelpLayerLight.visible = false;
clippingHelpLayerLight.duplicate();
var clippingHelpLayerLighter = doc.activeLayer;
clippingHelpLayerLighter.name = "Clipping Help Layer - Lighter";
clippingHelpLayerLighter.visible = false;
function newCurve() {
var c_ADJ_LAYER = charIDToTypeID("AdjL");
var c_ADJUSTMENT = charIDToTypeID("Adjs");
var c_CHANNEL = charIDToTypeID("Chnl");
var c_COMPOSITE = charIDToTypeID("Cmps");
var c_CURVE = charIDToTypeID("Crv ");
var c_CURVE_A = charIDToTypeID("CrvA");
var c_CURVES = charIDToTypeID("Crvs");
var c_HORIZONTAL = charIDToTypeID("Hrzn");
var c_MAKE = charIDToTypeID("Mk ");
var c_NULL = charIDToTypeID("null");
var c_POINT = charIDToTypeID("Pnt ");
var c_TYPE = charIDToTypeID("Type");
var c_USING = charIDToTypeID("Usng");
var c_VERTICAL = charIDToTypeID("Vrtc");
var d_CURVES_LAYER = new ActionDescriptor();
// Contains all the information necessary to perform the "MAKE" action
var r_CLASS = new ActionReference();
r_CLASS.putClass(c_ADJ_LAYER);
d_CURVES_LAYER.putReference(c_NULL, r_CLASS);
// Class of make action is of an ajdustment layer
var d_TYPE_CURVES = new ActionDescriptor();
// Contains all the information about all the curves
var d_CHANNEL_CURVES = new ActionDescriptor();
var l_CHANNEL_CURVES = new ActionList();
// Contains a list of channel curves
var d_CHANNEL_CURVE = new ActionDescriptor();
// Information for 1 channel curve
var r_CHANNEL = new ActionReference();
r_CHANNEL.putEnumerated(c_CHANNEL, c_CHANNEL, c_COMPOSITE);
// This curve is for the composite channel - VARIES
d_CHANNEL_CURVE.putReference(c_CHANNEL, r_CHANNEL);
// Contains the point list
var l_POINTS = new ActionList();
// List of points for this channel - LENGTH VARIES
var d_POINT = new ActionDescriptor();
// One point on the curve, has INPUT and OUTPUT value
d_POINT.putDouble(c_HORIZONTAL, 0.000000);
d_POINT.putDouble(c_VERTICAL, 0.000000);
l_POINTS.putObject(c_POINT, d_POINT);
//var d_POINT3 = new ActionDescriptor();
d_POINT.putDouble(c_HORIZONTAL, 255.000000);
d_POINT.putDouble(c_VERTICAL, 255.000000);
l_POINTS.putObject(c_POINT, d_POINT);
// Made the list of points
d_CHANNEL_CURVE.putList(c_CURVE, l_POINTS);
// Now have a list of points for a specific channel
l_CHANNEL_CURVES.putObject(c_CURVE_A, d_CHANNEL_CURVE);
// Add to the list of channel curves
d_CHANNEL_CURVES.putList(c_ADJUSTMENT, l_CHANNEL_CURVES);
// All the channel curves are inside here
d_TYPE_CURVES.putObject(c_TYPE, c_CURVES, d_CHANNEL_CURVES);
// .....
d_CURVES_LAYER.putObject(c_USING, c_ADJ_LAYER, d_TYPE_CURVES);
// package the curves and definition of the adjustment layer type
executeAction(c_MAKE, d_CURVES_LAYER, DialogModes.NO);
}
I actually want to create a first layer called "Clipping Help Layer - Light", blend mode : screen and turn it off. Then duplicate it, change the name of the new layer as "Clipping Help Layer - Lighter" and turn it off too.
Like this : Screenshot of what I would like to do
It does create the 2 layers, but the first one has " copy" at the end of its name and it stays turned on.
Screenshot of the actual result
Why ?
I can't understand why it doesn't work as expected and can't manage to fix it.
Any help would be greatly appreciated !
I believe the problem you are encountering has to do with doc.activeLayer. After you duplicate "Clipping Help Layer - Light," the script does not seem to change what doc.activeLayer is pointing to so when you then try to assign it to clippingHelpLayerLighter, you are then pointing at an undefined layer. While I don't know exactly what is happening behind the scenes when you do that, I do believe this will fix your problem:
#target photoshop
app.bringToFront();
var doc = app.documents.add( 4, 4 );
doc = app.activeDocument;
var clippingHelpLayerLight = doc.activeLayer;
clippingHelpLayerLight.blendMode = BlendMode.SCREEN;
clippingHelpLayerLight.name = "Clipping Help Layer - Light";
clippingHelpLayerLight.visible = false;
clippingHelpLayerLight.duplicate();
doc.activeLayer = doc.layers[ "Clipping Help Layer - Light copy" ];
doc.activeLayer.name = "Clipping Help Layer - Lighter";
doc.activeLayer.visible = false;
//I am not sure if you need this pointer to be called upon later in your
//code. If you do not, just leave this line out.
var clippingHelpLayerLighter = doc.activeLayer;
Hope this helps! Let me know if you have any questions, I'm by no means an expert but I use scripts fairly often.

EPiServer 9 - Add block to new page programmatically

I have found some suggestions on how to add a block to a page, but can't get it to work the way I want, so perhaps someone can help out.
What I want to do is to have a scheduled job that reads through a file, creating new pages with a certain pagetype and in the new page adding some blocks to a content property. The blocks fields will be updated with data from the file that is read.
I have the following code in the scheduled job, but it fails at
repo.Save((IContent) newBlock, SaveAction.Publish);
giving the error
The page name must contain at least one visible character.
This is my code:
public override string Execute()
{
//Call OnStatusChanged to periodically notify progress of job for manually started jobs
OnStatusChanged(String.Format("Starting execution of {0}", this.GetType()));
//Create Person page
PageReference parent = PageReference.StartPage;
//IContentRepository contentRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
//IContentTypeRepository contentTypeRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentTypeRepository>();
//var repository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
//var slaegtPage = repository.GetDefault<SlaegtPage>(ContentReference.StartPage);
IContentRepository contentRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
IContentTypeRepository contentTypeRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentTypeRepository>();
SlaegtPage slaegtPage = contentRepository.GetDefault<SlaegtPage>(parent, contentTypeRepository.Load("SlaegtPage").ID);
if (slaegtPage.MainContentArea == null) {
slaegtPage.MainContentArea = new ContentArea();
}
slaegtPage.PageName = "001 Kim";
//Create block
var repo = ServiceLocator.Current.GetInstance<IContentRepository>();
var newBlock = repo.GetDefault<SlaegtPersonBlock1>(ContentReference.GlobalBlockFolder);
newBlock.PersonId = "001";
newBlock.PersonName = "Kim";
newBlock.PersonBirthdate = "01 jan 1901";
repo.Save((IContent) newBlock, SaveAction.Publish);
//Add block
slaegtPage.MainContentArea.Items.Add(new ContentAreaItem
{
ContentLink = ((IContent) newBlock).ContentLink
});
slaegtPage.URLSegment = UrlSegment.CreateUrlSegment(slaegtPage);
contentRepository.Save(slaegtPage, EPiServer.DataAccess.SaveAction.Publish);
_stopSignaled = true;
//For long running jobs periodically check if stop is signaled and if so stop execution
if (_stopSignaled) {
return "Stop of job was called";
}
return "Change to message that describes outcome of execution";
}
You can set the Name by
((IContent) newBlock).Name = "MyName";

How to create fishnet in arcgis engine?

I found createfishnet method in arcobject, but it doesn't work.Where is my mistake?
Geoprocessor gp = new Geoprocessor();
gp.OverwriteOutput = true;
ESRI.ArcGIS.DataManagementTools.CreateFishnet fishnet = new ESRI.ArcGIS.DataManagementTools.CreateFishnet();
fishnet.template = buffer_out;
//txtOutputPath2.Text="E:\\program\\shenzhen_science_committee\\sc\\landuse_subway\\shenzhen_subway\\23_net.shp"
fishnet.out_feature_class = txtOutputPath2.Text;
IFeatureCursor cursor1=buffer_out.Search(null,true);
IFeature buffer=cursor1.NextFeature();
IPoint centerPoint =new ESRI.ArcGIS.Geometry.Point();
IArea pArea = buffer.Shape as IArea;
pArea.QueryCentroid(centerPoint);
fishnet.origin_coord = centerPoint;
double height=0;
double width=0;
fishnet.cell_height = 0.1;
fishnet.cell_width = 0.1;
fishnet.number_columns = 50;
fishnet.number_rows = 50;
IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(fishnet, null);
The result shows wrong HRESULT E_FAIL.
I have tried this in ArcObjects with Java. What I found was that the fishnet could not be generated for area within a particular polygon, as in the ArcMap application. You would have to intersect or use spatial filter on the fishnet output.
Also, try giving all the parameters, even the optional ones like set corner coordinate. If you are using data in a particular projection system, that can be set to the output by setting the template (and this takes only Envelope).
Below is the code that I have used. I wanted the fishnet label as well, so I have enabled it. Make sure you use a space between the x and y coordinate of a point, entered as a String, which is probably the issue here.
GeoProcessor gp = new GeoProcessor();
gp.setOverwriteOutput(true);
IEnvelope aoi = buffer_out.getEnvelope();
CreateFishnet createFishnet = new CreateFishnet();
createFishnet.setOutFeatureClass(tempDir+"/"+fishnetOutput+".shp");
createFishnet.setTemplate(aoi);
createFishnet.setOriginCoord(aoi.getXMin()+" "+aoi.getYMin());
createFishnet.setYAxisCoord(aoi.getXMin()+" "+aoi.getYMax());
createFishnet.setCornerCoord(aoi.getXMax()+" "+aoi.getYMax());
createFishnet.setCellHeight(30.0);
createFishnet.setCellWidth(30.0);
createFishnet.setNumberRows(0);
createFishnet.setNumberColumns(0);
createFishnet.setLabels("LABELS");
createFishnet.setGeometryType("POLYLINE");
gp.execute(createFishnet, null);
I hope you can use this example and apply it to your code.

Adobe Illustrator - Scripting crashes when trying to fit to artboards command

activeDocument.fitArtboardToSelectedArt()
When calling this command, AI crashes on AI 5.1/6 32bit and 64bit versions. I can use the command from the menu. Has anyone encountered this? does anyone know of a work around?
The full code.
function exportFileToJPEG (dest) {
if ( app.documents.length > 0 ) {
activeDocument.selectObjectsOnActiveArtboard()
activeDocument.fitArtboardToSelectedArt()//crashes here
activeDocument.rearrangeArtboards()
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
var fileSpec = new File(dest);
exportOptions.antiAliasing = true;
exportOptions.qualitySetting = 70;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
}
var file_name = 'some eps file.eps'
var eps_file = File(file_name)
var fileRef = eps_file;
if (fileRef != null) {
var optRef = new OpenOptions();
optRef.updateLegacyText = true;
var docRef = open(fileRef, DocumentColorSpace.RGB, optRef);
}
exportFileToJPEG ("output_file.jpg")
I can reproduce the bug with AI CS5.
It seems that fitArtboardToSelectedArt() takes the index of an artboard as an optional parameter. When the parameter is set, Illustrator doesn't crash. (probably a bug in the code handling the situation of no parameter passed)
As a workaround you could use:
activeDocument.fitArtboardToSelectedArt(
activeDocument.artboards.getActiveArtboardIndex()
);
to pass the index of the active artboard with to the function. Hope this works for you too.
Also it's good practice to never omit the semicolon at the end of a statement.