Author Topic: XCLIP 3d References c# .NET  (Read 2744 times)

0 Members and 2 Guests are viewing this topic.

matinau

  • Guest
XCLIP 3d References c# .NET
« on: March 13, 2013, 11:40:07 PM »
Hi
Anyone had any success XCLIPPING both 2d and 3d references using .NET ?

I found an excellent post by Kean Walmsley here covering 2d references http://through-the-interface.typepad.com/through_t​he_interface/au/page/4/

How can I cater for 3d references?
The "SpatialFilterDefinition" contains all the juice, but I haven't managed to succesfully pass elevation and clipping depths.

SpatialFilterDefinitionsfd = newSpatialFilterDefinition(pts, Vector3d.ZAxis, 0.0, 0.0, 0.0, true);

thanks in advance
..

matinau

  • Guest
Re: XCLIP 3d References c# .NET
« Reply #1 on: March 16, 2013, 03:03:16 AM »
Thought I should put the portion of the code up I'm having trouble with:

// Transform points to selected clipping block ucs
pt1 = pt1.TransformBy(selectedBlock.BlockTransform);
pt2 = pt2.TransformBy(selectedBlock.BlockTransform);
pt3 = pt3.TransformBy(selectedBlock.BlockTransform);
pt4 = pt4.TransformBy(selectedBlock.BlockTransform);

var ms = (BlockTableRecord) tr.GetObject(SymbolUtilityServices.GetBlockModelSp​aceId(db), OpenMode.ForRead);

foreach (ObjectId id in ms)
{
 var ent = (Entity) tr.GetObject(id, OpenMode.ForRead);

 if (ent != null)
 {
  if (ent.GetType() == typeof (BlockReference))
  {
   var br = (BlockReference) ent; // Get block reference

   var btr = (BlockTableRecord) tr.GetObject(br.BlockTableRecord, OpenMode.ForRead);

   // Check whether the blockreference is an external reference
   if (btr.IsFromExternalReference && btr.IsResolved)
   {
    var pts = new Point2dCollection(4)
     {
      new Point2d(pt1.X, pt1.Y),
      new Point2d(pt2.X, pt2.Y),
      new Point2d(pt3.X, pt3.Y),
      new Point2d(pt4.X, pt4.Y)
     };

    // Create spatial filter
    var sfd = new SpatialFilterDefinition(pts, Vector3d.ZAxis, 0.0, 0.0, 0.0, true);
   
    var sf = new SpatialFilter {Definition = sfd};

    // Create extension dictionary if doesn't exist
    if (br.ExtensionDictionary == ObjectId.Null)
    {
     br.UpgradeOpen();
     br.CreateExtensionDictionary();
     br.DowngradeOpen();
    }

    // Add spatial filter to extension dictionary
    var extDict = (DBDictionary) tr.GetObject(br.ExtensionDictionary, OpenMode.ForWrite);

    if (extDict.Contains(filterDictName))
    {
     var filterDict = (DBDictionary) tr.GetObject(extDict.GetAt(filterDictName), OpenMode.ForWrite);

     if (filterDict.Contains(spatialName))
      filterDict.Remove(spatialName);

     filterDict.SetAt(spatialName, sf);
    }
    else
    {
     var filterDict = new DBDictionary();
     extDict.SetAt(filterDictName, filterDict);
     tr.AddNewlyCreatedDBObject(filterDict, true);
     filterDict.SetAt(spatialName, sf);
    }

    tr.AddNewlyCreatedDBObject(sf, true);
   }
  }
 }
}

tr.Commit();


WILL HATCH

  • Bull Frog
  • Posts: 450
Re: XCLIP 3d References c# .NET
« Reply #2 on: March 16, 2013, 02:38:43 PM »
From definition:
Code - C#: [Select]
  1. public SpatialFilterDefinition(Point2dCollection pts, Vector3d normal, double elevation, double frontClip, double backClip, bool enabled);

I think it's because you're setting the front and back clip values to both be 0

If I remember correctly from setting those items in the viewport properties it would throw an error if you tried to set both to the same value.

EDIT:
After looking at the code you copied from I see this is exactly how they did it.  What is the error? Maybe try using the empty constructor and setting each value after in it's own instruction allowing you to get a better idea of the source.
« Last Edit: March 16, 2013, 02:57:00 PM by WILL HATCH »

matinau

  • Guest
Re: XCLIP 3d References c# .NET
« Reply #3 on: March 19, 2013, 04:33:20 AM »
I'll give it ago thanks. I'm not getting a runtime error but clipped 3d references jump out side the defined clipping boundary whereas 2d references clip fine?