.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Handling ''REFEDIT" from a pluggin using .NET

5 REPLIES 5
Reply
Message 1 of 6
dominicthoppil
992 Views, 5 Replies

Handling ''REFEDIT" from a pluggin using .NET

Hi

            I am trying to create one pluggin which can handle inplace edit [refedit]. I can open in place edit window by inovking 'REFEDIT' command from my pluggin. But i need to get the selected document path for in place edit. 

Is there any solution for this which i can do from a my .net pluggin.

 

 

 

Regards

Dominic

5 REPLIES 5
Message 2 of 6

Are you looking for the BlockTableRecord.PathName property? If that just returns a filename without path, then you can pass that to HostApplicationServices.Current.FindFile to find the path to the file.

Cheers,

Stephen Preston
Autodesk Developer Network
Message 3 of 6

Hi

     Thank you for your reply. If my understanding is correct, BlockTableRecord will return the list of external reference drawings attached to the main drawing.  Hope you have seen the attached image with my previous post. Actualy i need to get the selected drawing name (full path) selected for in place edit. I have 10 external reference drawing to my main drawing. After opening my main drawing , i will select one particular drawing for in-place edit. I need to get the name  with path of that selected drawing. I tried different possibilities. I think, the command 'REFEDITNAME' will give the name of the selected external reference drawing for in place edit. But i dont know how to use the 'REFEDITNAME' in my code. When i executed the command from  my code using SendCommand(), it exectued. But how to capture the result  in my code. Ie. assiging the result to some variable in my code .?

 

 

Regards

Dominic

Message 4 of 6

If you are programming AutoCAD using the .NET API, you generally don't use commands to solve problems. You should probably download all of the API training materials if you've not done that already, and go through them. The API is very complex and takes some time to learn, but for starters, the way to find the filename of a loaded, resolved xref is not by using the BlockTableRecord's PathName property. You can fall-back to using the PathName if the xref is not loaded or resolved, but otherwise, You get the filename of the xref by calling the BlockTableRecord's GetXrefDatabase() method, which returns the Database object for the Xef, and then you just read the Database object's Filename property.

 

Given a BlockReference object that represents an insertion of the xref, here is the C# code that produces the name of the drawing file:

 

using System.IO;

// A best practice is to place extension methods in the
// same namespace as their invocation target:

namespace Autodesk.AutoCAD.DatabaseServices
{
   public static class BlockReferenceExtensions
   {
      // Returns the xref filename for the given XREF block reference:
      //
      // - Requires an active transaction. 
      // - Returns an empty string if the given BlockReference is not 
      //   an xref or overlay reference, or is unresolved and the file
      //   cannot be found.

      public static string GetXrefFilename( this BlockReference blockref )
      {
         string result = string.Empty;
         BlockTableRecord btr = (BlockTableRecord)
            blockref.DynamicBlockTableRecord.GetObject( OpenMode.ForRead );
         if( btr.IsFromExternalReference || btr.IsFromOverlayReference )
         {
            if( !btr.IsUnloaded && btr.XrefStatus == XrefStatus.Resolved )
            {
               using( Database db = btr.GetXrefDatabase( false ) )
               {
                  if( db != null )
                     result = db.Filename;
               }
            }
            else
            {
               try
               {
                  result = HostApplicationServices.Current.FindFile( 
                     btr.PathName, btr.Database, FindFileHint.XRefDrawing );
               }
               catch    // don't know why, but FindFile throws an exception 
               {        // if the file is not found.
               }
            }
         }
         return result;
      }

   }
}

 

 

    

Message 5 of 6

Hi

 

    Thank you for your reply. I will try to understand more by using API guide.

I am able to read the external reference documents path. But my issue is different from that. If i have 10 drawings attached to the main drawing, i can read the path of all drawings.XrefStatus.Resolved is true for all. But i need to get the single one which is selected for in place edit. When i select one drawing, the SelectionAdded event will get fired. But e.AddedObjects.GetObjectIds() is not match with object ids from BlockTable. Is there any specific method or properites, which will give the same result as REFEDITNAME command gives ?

 

 

Regards

Dominic Abraham

Message 6 of 6

Like I mentioned previously, your main problem is that you're not familiar with the API.

 

The objects that are selected are BlockReference objects, which are the INSERT entities that you create using the INSERT or XREF ATTACH command. The code I posted shows how to get the BlockTableRecord object for a given BlockReference, and that's where you're confused.  You have to look at the BlockReference objects that are selected, and from them you can find the BlockTableRecord object for the selected block, from which you can get the path.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost