Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with GeneralDimensions.AddLinear an SketchLine3D

1 REPLY 1
Reply
Message 1 of 2
ASchroeder
556 Views, 1 Reply

Problem with GeneralDimensions.AddLinear an SketchLine3D

The DrawingView show an Construction with a occurence, which hold an 3DSketch with 3DSketchLines. This 3DSketchLines are the Elements, which are identified by startPoint and endPoint. This Lines are the geometrical objects which i have to dimension. The sketch with this Lines would be included as Sketch3DProxy in oBaseView (and all SketchLine3D as SketchLine3DProxy too, but I'm not shure if have to do this).

 

The Script found the correct Lines, the Sketch are included, the GeometryIntent are created but the GeneralDimensions.AddLinear-function are failed. I have tried various methods to create the Intent, but nothing changed. Every call failed.

 

Anyone who know a solution for this problem?

 

Thanks

 

AS

 

PS: startPoint and endPoint are own Objects with X,Y and Z Values in mm

 

public void DrawDimension(
            Point startPoint,
            Point endPoint)
{
if (_oDrawDoc.DocumentType == DocumentTypeEnum.kDrawingDocumentObject && _oActiveSheet != null)
{
     DrawingView oBaseView = _oActiveSheet.DrawingViews[1];
     Inventor.TransientGeometry oTG;
     oTG = _InvApp.TransientGeometry;

     Inventor.DimensionStyle oDimStyle = null;
     Inventor.Layer oDimLayer = null;

     try
     {
         oDimLayer = _oDrawDoc.StylesManager.Layers[dimStyleName];
         oDimStyle = _oDrawDoc.StylesManager.DimensionStyles[layerName];
     }
     catch
     {
         oDimLayer = _oDrawDoc.StylesManager.Layers["Bemaßung (ISO)"];
         oDimStyle = _oDrawDoc.StylesManager.DimensionStyles["Standard Linear-SINGLE"];
     }

      //jetzt Liniensegment suchen
     try
     {
          //skizze finden und mit einbinden;
          Sketch3D Sketch = null;
          Sketch3DProxy SketchProxy = null;
          Object tempProxy = null;
          ComponentOccurrence oOcc = null;

          if (_RoutingDocument != null && _RoutingDocument.ComponentDefinition.Sketches3D.Count.Equals(1))
          {
               ComponentOccurrences oOccs =                            ((AssemblyDocument)oBaseView.ReferencedDocumentDescriptor.ReferencedDocument).ComponentDefinition.Occurrences;
               for (int i = 1; i <= oOccs.Count; i++)
               {
                    if (oOccs[i].Definition.Document.Equals(_RoutingDocument))
                    {
                          oOcc = oOccs[i];
                          oOccs[i].CreateGeometryProxy(((PartDocument)oOccs[i].Definition.Document).ComponentDefinition.Sketches3D[1], out tempProxy);
                          SketchProxy = (Sketch3DProxy)tempProxy;
                          oBaseView.SetIncludeStatus(SketchProxy, true);
                                   
                          foreach (SketchLine3D sline in ((PartDocument)oOccs[i].Definition.Document).ComponentDefinition.Sketches3D[1].SketchLines                          {
                              try
                              {
                                   Object tmpObj = null;
                                   SketchLine3DProxy slineProxy = null;
                                            
                                   oOccs[i].CreateGeometryProxy(sline, out tmpObj);

                                   slineProxy = (SketchLine3DProxy)tmpObj;
                                   try
                                   {
                                        oBaseView.SetIncludeStatus(slineProxy, true);
                                   }
                                   catch { }
                                }
                                catch { }
                            }

                            break;
                      }
                }
                _oActiveSheet.Update();
            }

            SketchLine3DProxy dimLine = null;
            Point invStartPoint = oTG.CreatePoint(startPoint.X / 10, startPoint.Y / 10, startPoint.Z / 10);
            Point invEndPoint = oTG.CreatePoint(endPoint.X / 10, endPoint.Y / 10, endPoint.Z / 10);
            foreach (SketchLine3DProxy line in SketchProxy.SketchLines3D)
            {
                if (((SketchPoint3D)line.StartPoint).Geometry.DistanceTo(invStartPoint) < 0.01 ||                                ((SketchPoint3D)line.StartPoint).Geometry.DistanceTo(invEndPoint) < 0.01)
                {
                      if (((SketchPoint3D)line.StartPoint).Geometry.DistanceTo(invStartPoint) < 0.01 &&                                    ((SketchPoint3D)line.EndPoint).Geometry.DistanceTo(invEndPoint) < 0.01)
                           dimLine = line;
                      if (((SketchPoint3D)line.EndPoint).Geometry.DistanceTo(invStartPoint) < 0.01 &&                                    ((SketchPoint3D)line.StartPoint).Geometry.DistanceTo(invEndPoint) < 0.01)
                           dimLine = line;
                 }
                 if (dimLine != null)
                 {                                
                       break;
                 }
             }
             try
             {
                 Inventor.GeometryIntent oStart = null;
                 Inventor.GeometryIntent oEnd = null;
                 Inventor.DrawingCurve oCurve = null;
                           
                 foreach (Inventor.DrawingCurve Curve in
                                oBaseView.get_DrawingCurves(null))
                 {
                     Boolean bUseThis = false;
                     if (Curve.CurveType != CurveTypeEnum.kLineCurve &&
                         Curve.CurveType != CurveTypeEnum.kLineSegmentCurve)
                                    continue;
                     if (Curve.ModelGeometry is SketchLine3DProxy)
                     {
                         try
                         {
                             SketchLine3DProxy tmpLine = (SketchLine3DProxy)Curve.ModelGeometry;

                             if (tmpLine.Equals(dimLine))
                             {
                                  foreach (Inventor.DrawingCurveSegment oSeg in Curve.Segments)
                                  {
                                       String strLayer = oSeg.Layer.Name;
                                       if ((strLayer == "3D Skizziergeometrie (ISO)")) //&& (oSeg.StartPoint.Y == oSeg.EndPoint.Y))
                                       {
                                            bUseThis = true;
                                       }
                                  }
                              }
                          }
                          catch { }
                      }

                      if (bUseThis == true)
                      {
                          oCurve = Curve;
                          break;
                      }
                 }
                 if (oCurve == null)
                      return;

                 oStart = _oActiveSheet.CreateGeometryIntent(oCurve.StartPoint, Inventor.PointIntentEnum.kStartPointIntent);
                 oEnd = _oActiveSheet.CreateGeometryIntent(oCurve.EndPoint, Inventor.PointIntentEnum.kEndPointIntent);

                 double TextX = oCurve.MidPoint.X;
                 double TextY = oCurve.MidPoint.Y + 0.25;

                 try
                 {
                      //this one failed (oStart and oEnd are not Correct, but how can i fix this?              
_oActiveSheet.DrawingDimensions.GeneralDimensions.AddLinear(oTG.CreatePoint2d(TextX, TextY),oStart, oEnd, Inventor.DimensionTypeEnum.kAlignedDimensionType, true, null, null);
                 }
                 catch { }
             }
             catch{}
         }
         catch{ }
         finally { }
    }
}

 

 

 

1 REPLY 1
Message 2 of 2
ASchroeder
in reply to: ASchroeder

Nobody, who know what to do? Or is it impossible?

 

Thanks

AS

 

PS: we use Inventor in Version 2011 and 2012 soon

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report