OnResolveXRefEvent

Discuss and ask questions about CAD .NET library.

Moderators: admin, support, SDS

OnResolveXRefEvent

Postby dor_r@top-s.co.il » 07 Feb 2017, 21:33

Hi Guys,
I need some documentation on How OnResolveXRefEvent event works
Can I use it to resolve xrefs which are not found on same dir or on original location?
If not I need a way to manually load xrefs

I'm trying to use this code but the xref is not resolved on the image.
Do I need to reload/refresh etc?
Do I do something wrong:

private static bool Converter_OnResolveXRefEvent(CADXRef AXref, string AFileName, ref bool AIsResolve)
{
AXref.AddCADImage(....Path to the current location of xref .....);
AIsResolve = true;
return true;


Thanks Dror
dor_r@top-s.co.il
 
Posts: 8
Joined: 17 Jan 2017, 15:58

Re: OnResolveXRefEvent

Postby support » 10 Feb 2017, 19:56

Hello Dror,

The OnResolveXRefEvent occurs if some XRef can't be found at its path during the loading of drawing file.
AXRef returns CADXRef object for the unresolved XRef,
AFileName contains a path of the unresolved XRef,
AIsResolve flag value is equal false.

The unresolved XRef should be resolved in the OnResolveXRefEvent handler as shown below.

Code: Select all
CADImage cadImage;
...
cadImage.Converter.OnResolveXRefEvent += new CADXRefResolver(Converter_OnResolveXRefEvent);
...

bool Converter_OnResolveXRefEvent(CADXRef AXref, string AFileName, ref bool AIsResolve)
{
    string xRefPath = @"C:\new_xref_folder\new_xref_file.dwg";
    if (System.IO.File.Exists(xRefPath))
    {
        AXref.AddCADImage(xRefPath);
        cadImage.AddScaledDXF(AXref.CADImage, xRefPath, new DPoint(0, 0, 0), new DPoint(1, 1, 1), 0);
        AIsResolve = true;
    }
    return AIsResolve;
}

This code actually adds a new XRef to the loaded CADImage (cadImage variable), so you will need to delete the old (unresolved) XRef, its block and insert afterwards. Unfortunately, it is not possible to modify the unresolved XRef in the event handler, because the entities are not accessible when the OnResolveXRefEvent occurs.


Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
support
 
Posts: 2706
Joined: 30 Mar 2005, 08:36

Re: OnResolveXRefEvent

Postby dor_r@top-s.co.il » 12 Feb 2017, 08:24

Thanks.
But we still have a major problem. The new XREF is not in the right position, sizing, rotation etc.
Is there a way to copy all sizing, position definition from the unresolved reference?
Or on the other side (which will make things VERY easy) to make the AFileName passes by ref?

Dror
dor_r@top-s.co.il
 
Posts: 8
Joined: 17 Jan 2017, 15:58

Re: OnResolveXRefEvent

Postby support » 13 Feb 2017, 15:41

Dror,

We are aware of this problem. The position, scale and rotation angle of the unresolved external reference can't be retrieved in the OnResolveXRefEvent handler, because these parameters should be retrieved from XRef's insert (CADInsert object), but this insert is not accessible when the event occurs.

Or on the other side (which will make things VERY easy) to make the AFileName passes by ref?

Could you explain how you can benefit from the AFileName parameter passed by reference? Do you want to be able to resolve an external reference by simply changing the file name in the event handler?


Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
support
 
Posts: 2706
Joined: 30 Mar 2005, 08:36

Re: OnResolveXRefEvent

Postby dor_r@top-s.co.il » 13 Feb 2017, 15:51

Yes. Exactly.
The xrefs are located in a different directory and different name than the original name it appears in the original model. I have a translation table between the original name and the new name. so for instance what I want to achieve is something like:

private static bool Converter_OnResolveXRefEvent(CADXRef AXref, string AFileName, ref bool AIsResolve)
{
string originalName = AFileName;
string newLoationAndName = findXrefNewLocation(originalName );
if(!string.isNullOrEmpty(newLoationAndName) // if found new xref location
{
AFileName = newLoationAndName ;
AIsResolve=true;
return AIsResolve;

}


AIsResolve = false;
return false;
dor_r@top-s.co.il
 
Posts: 8
Joined: 17 Jan 2017, 15:58

Re: OnResolveXRefEvent

Postby support » 13 Feb 2017, 16:08

Dror,

Thank you for the information.

Currently it is not possible to resolve the XRef by simply changing its file name in the OnResolveXRefEvent handler. But we will take your suggestion into account.


Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
support
 
Posts: 2706
Joined: 30 Mar 2005, 08:36

Re: OnResolveXRefEvent

Postby support » 16 Feb 2017, 16:19

Hello Dor,

We have modified the OnResolveXRefEvent and its delegate as follows:

Code: Select all
public static event CADXRefResolver OnResolveXRefEvent;


Code: Select all
namespace CADImport
{
    public delegate void CADXRefResolver(ref string xrefPath);
}

The xrefPath parameter is passed by reference, so now you can resolve an external reference by changing its path in the event handler. The code example below shows how to use the modified OnResolveXRefEvent.

Code: Select all
using CADImport;
...

public Form1()
{
    InitializeComponent();
    CADConverter.OnResolveXRefEvent += new CADXRefResolver(CADConverter_OnResolveXRefEvent);
}

void CADConverter_OnResolveXRefEvent(ref string xrefPath)
{
    string newXRefPath =@"C:\new_xref_folder\new_xref_file.dwg";
    if (System.IO.File.Exists(newXRefPath))
    {
        xrefPath = newXRefPath;
    }
}

The modified event is available in version 11.2.20.61206 which was sent to you via e-mail.


Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
support
 
Posts: 2706
Joined: 30 Mar 2005, 08:36


Return to CAD .NET

Who is online

Users browsing this forum: No registered users and 9 guests

cron