Revit: Cannot create dimensions when ViewSection is rotated - dimensions

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.

Related

Illustrator script (or action) to make 1 random layer visible per group

Similar to this question but with adobe Illustrator: Photoshop action to make 1 random layer visible within each group
I want to use an illustrator script (or action) to generate images that are composed of a random sampling of grouped layers.
With in each of the 12 groups, I want to make 1 layer per group visible.
Export the visible layers as an svg. Bonus points if I can change the file format.
Repeat the process n times
I know this is similar to the code linked above though I want to be able to use illustrator instead of photoshop if possible.
It could be something like this:
function main() {
var doc = app.activeDocument;
// hide all items
var i = doc.pageItems.length;
while(i--) doc.pageItems[i].hidden = true;
// show one random item on every layer
var i = doc.layers.length;
while(i--) {
var items = doc.layers[i].pageItems;
var index = Math.round(Math.random()*(items.length-1));
items[index].hidden = false;
}
// save svg
var counter = 0;
var file = File(Folder.desktop + '/' + counter + '.svg') ;
while (file.exists) {
file = File(Folder.desktop + '/' + counter++ + '.svg');
}
doc.exportFile(file, ExportType.SVG);
// save png
var counter = 0;
var file = File(Folder.desktop + '/' + counter + '.png') ;
while (file.exists) {
file = File(Folder.desktop + '/' + counter++ + '.png');
}
var options = new ExportOptionsPNG24();
options.artBoardClipping = true;
doc.exportFile(file, ExportType.PNG24, options);
}
// repeat the script N times
var n = 3;
while(n--) main();
It hides all the page items, shows one random item on every layer, and saves the document as SVG and PNG in the desktop folder.

Why does adding w:drawing cause corrupted file

I'm trying to add a chart to a docx file using docx4j. I generated what i wanted in Word and with the help of the docx4j webapp i was able to get the corresponding java code. Unfortunately the generated docx file is said to be corrupted by Word. When trying to debug, I realised that if I commented out the line that added the drawing to the run, the file became readable. I can't figure out what's wrong. Below is my code and the link to what i tried to reproduce http://www.filedropper.com/graphique .
I'm using docx4j 8.2 and office 2016
Chart chartPart = new Chart();
Relationship chartRelationship = wordMLPackage.getMainDocumentPart().addTargetPart(chartPart);
chartPart.setJaxbElement(ChartSpace.createChartSpace());
DefaultXmlPart colorPart = new DefaultXmlPart(new PartName("/word/charts/colors1.xml"));
colorPart.setContentType(new ContentType("application/vnd.ms-office.chartcolorstyle+xml"));
colorPart.setRelationshipType("http://schemas.microsoft.com/office/2011/relationships/chartColorStyle");
chartPart.addTargetPart(colorPart);
colorPart.setDocument(new FileInputStream(new File("colors1.xml")));
DefaultXmlPart stylePart = new DefaultXmlPart(new PartName("/word/charts/style1.xml"));
stylePart.setContentType(new ContentType("application/vnd.ms-office.chartstyle+xml"));
stylePart.setRelationshipType("http://schemas.microsoft.com/office/2011/relationships/chartStyle");
chartPart.addTargetPart(stylePart);
stylePart.setDocument(new FileInputStream(new File("style1.xml")));
EmbeddedPackagePart embeddedPackagePart = new EmbeddedPackagePart(
new PartName("/word/embeddings/Microsoft_Excel_Worksheet.xlsx"));
embeddedPackagePart.setContentType(
new ContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
chartPart.addTargetPart(embeddedPackagePart);
embeddedPackagePart.setBinaryData(new java.io.FileInputStream(new File("data.xlsx")));
mainDocumentPart.getContent().add(addGraphic(factory, chartRelationship.getId()));
public static P addGraphic(ObjectFactory factory, String chartId) throws JAXBException {
P p = factory.createP();
// Create object for r
R r = factory.createR();
p.getContent().add(r);
// Create object for drawing (wrapped in JAXBElement)
Drawing drawing = factory.createDrawing();
JAXBElement<org.docx4j.wml.Drawing> drawingWrapped = factory.createRDrawing(drawing);
r.getContent().add(drawingWrapped);
org.docx4j.dml.wordprocessingDrawing.ObjectFactory dmlwordprocessingDrawingObjectFactory = new org.docx4j.dml.wordprocessingDrawing.ObjectFactory();
// Create object for inline
Inline inline = dmlwordprocessingDrawingObjectFactory.createInline();
drawing.getAnchorOrInline().add(inline);
org.docx4j.dml.ObjectFactory dmlObjectFactory = new org.docx4j.dml.ObjectFactory();
// Create object for graphic
Graphic graphic = dmlObjectFactory.createGraphic();
inline.setGraphic(graphic);
// Create object for graphicData
GraphicData graphicdata = dmlObjectFactory.createGraphicData();
graphic.setGraphicData(graphicdata);
graphicdata.setUri("http://schemas.openxmlformats.org/drawingml/2006/chart");
org.docx4j.dml.chart.ObjectFactory dmlchartObjectFactory = new org.docx4j.dml.chart.ObjectFactory();
// Create object for chart (wrapped in JAXBElement)
CTRelId relid = dmlchartObjectFactory.createCTRelId();
JAXBElement<org.docx4j.dml.chart.CTRelId> relidWrapped = dmlchartObjectFactory.createChart(relid);
graphicdata.getAny().add(relidWrapped);
relid.setId(chartId);
// Create object for cNvGraphicFramePr
CTNonVisualGraphicFrameProperties nonvisualgraphicframeproperties = dmlObjectFactory
.createCTNonVisualGraphicFrameProperties();
inline.setCNvGraphicFramePr(nonvisualgraphicframeproperties);
// Create object for extent
CTPositiveSize2D positivesize2d = dmlObjectFactory.createCTPositiveSize2D();
inline.setExtent(positivesize2d);
positivesize2d.setCx(5486400);
positivesize2d.setCy(3200400);
// Create object for effectExtent
CTEffectExtent effectextent = dmlwordprocessingDrawingObjectFactory.createCTEffectExtent();
inline.setEffectExtent(effectextent);
effectextent.setB(0);
effectextent.setL(0);
effectextent.setT(0);
effectextent.setR(0);
// Create object for docPr
CTNonVisualDrawingProps nonvisualdrawingprops = dmlObjectFactory.createCTNonVisualDrawingProps();
inline.setDocPr(nonvisualdrawingprops);
nonvisualdrawingprops.setDescr("");
nonvisualdrawingprops.setName("Graphique 1");
nonvisualdrawingprops.setId(1);
inline.setDistT(Long.valueOf(0));
inline.setDistB(Long.valueOf(0));
inline.setDistL(Long.valueOf(0));
inline.setDistR(Long.valueOf(0));
// Create object for rPr
RPr rpr = factory.createRPr();
r.setRPr(rpr);
// Create object for noProof
BooleanDefaultTrue booleandefaulttrue = factory.createBooleanDefaultTrue();
rpr.setNoProof(booleandefaulttrue);
return p;
}

three.js Unproject camera within group

I have a camera as child within a Group object and I need to get the origin/direction:
var cameraRig = new THREE.Group();
cameraRig.add( cameraPerspective );
cameraRig.add( cameraOrtho );
scene.add( cameraRig );
function relativeMousePosition () {
var canvasBoundingBox = renderer.domElement.getBoundingClientRect();
var mouse3D = new THREE.Vector3(0, 0, 0.5);
mouse3D.x = ((mouseX - 0) / canvasBoundingBox.width) * 2 - 1;
mouse3D.y = -((mouseY - 0) / canvasBoundingBox.height) * 2 + 1;
return mouse3D;
}
cameraRig.position.set(89,34,91);
cameraRig.lookAt(something.position);
cameraPerspective.position.set(123,345,123);
var dir = relativeMousePosition().unproject(camera).sub(cameraPerspective.position).normalize();
var origin = cameraPerspective.position;
The above code gives a origin + direction with the context of the cameraRig. When I exclude the camera out, having the scene as direct parent, it gives me the world origin/direction which I want. So how to incorporate the cameraRig to get world origin/direction, so I can do picking or whatever?
FIDDLE: https://jsfiddle.net/647qzhab/1/
UPDATE:
As mentioned in the comment by Falk:
var dir = relativeMousePosition().unproject(camera).sub(cameraPerspective.getWorldPosition()).normalize();
var origin = cameraPerspective.getWorldPosition();
The result is better, but not yet fully satisfiing, as the camera rotation seems not applied yet.
I need to update matrixWorld for the cameraRig:
cameraRig.position.set(89,34,91);
cameraRig.lookAt(something.position);
cameraPerspective.position.set(123,345,123);
cameraRig.updateMatrixWorld(true);
cameraPerspective.updateMatrixWorld(true);

Flex 3 - Enable context menu for text object under a transparent PNG

Here is the situation. In my app I have an overlay layer that is composed of a transparent PNG. I have replaced the hitarea for the png with a 1x1 image using the following code:
[Bindable]
[Embed(source = "/assets/1x1image.png")]
private var onexonebitmapClass:Class;
private function loadCompleteHandler(event:Event):void
{
// Create the bitmap
var onexonebitmap:BitmapData = new onexonebitmapClass().bitmapData;
var bitmap:Bitmap;
bitmap = event.target.content as Bitmap;
bitmap.smoothing = true;
var _hitarea:Sprite = createHitArea(onexonebitmap, 1);
var rect:flash.geom.Rectangle = _box.toFlexRectangle(sprite.width, sprite.height);
var drawnBox:Sprite = new FlexSprite();
bitmap.width = rect.width;
bitmap.height = rect.height;
bitmap.x = -loader.width / 2;
bitmap.y = -loader.height / 2;
bitmap.alpha = _alpha;
_hitarea.alpha = 0;
drawnBox.x = rect.x + rect.width / 2;
drawnBox.y = rect.y + rect.height / 2;
// Add the bitmap as a child to the drawnBox
drawnBox.addChild(bitmap);
// Rotate the object.
drawnBox.rotation = _rotation;
// Add the drawnBox to the sprite
sprite.addChild(drawnBox);
// Set the hitarea to drawnBox
drawnBox.hitArea = _hitarea;
}
private function createHitArea(bitmapData:BitmapData, grainSize:uint = 1):Sprite
{
var _hitarea:Sprite = new Sprite();
_hitarea.graphics.beginFill(0x900000, 1.0);
for (var x:uint = 0; x < bitmapData.width; x += grainSize)
{
for (var y:uint = grainSize; y < bitmapData.height; y += grainSize)
{
if (x <= bitmapData.width && y <= bitmapData.height && bitmapData.getPixel(x, y) != 0)
{
_hitarea.graphics.drawRect(x, y, grainSize, grainSize);
}
}
}
_hitarea.graphics.endFill();
return _hitarea;
}
This is based off the work done here: Creating a hitarea for PNG Image with transparent (alpha) regions in Flex
Using the above code I am able to basically ignore the overlay layer for all mouse events (click, double click, move, etc.) However, I am unable to capture the right click (context menu) event for items that are beneath the overlay.
For instance I have a spell check component that checks the spelling on any textitem and like most other spell checkers if the word is incorrect or not in the dictionary underlines the word in red and if you right click on it would give you a list of suggestions in the contextmenu. This is working great when the text box is not under the overlay, but if the text box is under the overlay I get nothing back.
If anyone can give me some pointers on how to capture the right click event on a textItem that is under a transparent png that would be great.

How to use datagraphwindow of arcgis programmatically

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.