.NET

.NET

Reply
Active Member
dominicthoppil
Posts: 9
Registered: ‎09-27-2012
Message 1 of 6 (429 Views)

Handling ''REFEDIT" from a pluggin using .NET

429 Views, 5 Replies
09-30-2012 12:36 AM

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

Board Manager
StephenPreston
Posts: 373
Registered: ‎05-22-2006
Message 2 of 6 (383 Views)

Re: Handling ''REFEDIT" from a pluggin using .NET

10-01-2012 01:51 PM in reply to: dominicthoppil

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
Active Member
dominicthoppil
Posts: 9
Registered: ‎09-27-2012
Message 3 of 6 (363 Views)

Re: Handling ''REFEDIT" from a plug-in using .NET

10-02-2012 10:19 PM in reply to: StephenPreston

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

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 4 of 6 (330 Views)

Re: Handling ''REFEDIT" from a plug-in using .NET

10-03-2012 04:42 PM in reply to: dominicthoppil

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;
      }

   }
}

 

 

    

Active Member
dominicthoppil
Posts: 9
Registered: ‎09-27-2012
Message 5 of 6 (305 Views)

Re: Handling ''REFEDIT" from a plug-in using .NET

10-04-2012 04:54 AM in reply to: DiningPhilosopher

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

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 6 of 6 (282 Views)

Re: Handling ''REFEDIT" from a plug-in using .NET

10-05-2012 02:57 AM in reply to: dominicthoppil

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.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.