Author Topic: Modifying path of XREF image  (Read 1948 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 184
Modifying path of XREF image
« on: October 19, 2018, 02:48:04 PM »
Hi everyone,

I would like to modify the path of an image external reference.  I'm able to do so but if I try to put a wrong path, I get an error message. 
Is there a way to do so ?
I'm able to put a bad path for PDF external reference so I thought I could do the same for image.

Code: [Select]
                            if (dictDB.Contains(pdfkey))
                            {
                                DBDictionary pdfDic = (DBDictionary)tr.GetObject(dictDB.GetAt(pdfkey), OpenMode.ForRead);

                                foreach (DBDictionaryEntry dbe in pdfDic)
                                {
                                    if (String.IsNullOrEmpty(dbe.m_key)) continue;

                                    UnderlayDefinition underlayDefinition = (UnderlayDefinition)tr.GetObject(dbe.Value, OpenMode.ForWrite);
                                    cOldFile = underlayDefinition.SourceFileName;
                                    if (aListXrefModif.Contains(cOldFile))
                                    {
                                        underlayDefinition.SourceFileName = aListXrefModif[cOldFile].ToString();
                                        nElementModif = nElementModif + 1;
                                    }
                                }
                            }

                            if (dictDB.Contains(imgkey))
                            {
                                DBDictionary imgDic = (DBDictionary)tr.GetObject(dictDB.GetAt(imgkey), OpenMode.ForRead);

                                foreach (DBDictionaryEntry dbe in imgDic)
                                {
                                    if (String.IsNullOrEmpty(dbe.m_key)) continue;

                                    RasterImageDef underlayDefinition = (RasterImageDef)tr.GetObject(dbe.Value, OpenMode.ForWrite);
                                    cOldFile = underlayDefinition.SourceFileName;
                                    if (aListXrefModif.Contains(cOldFile))
                                    {
                                        try
                                        {
                                            underlayDefinition.SourceFileName = aListXrefModif[cOldFile].ToString();
                                            nElementModif = nElementModif + 1;
                                        }
                                        catch {  }
                                    }
                                }
                            }

Thank you !

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Modifying path of XREF image
« Reply #1 on: October 20, 2018, 06:21:51 PM »
Not sure why you would want to put a bad path, but if you look at what ObjectArx docs and look at what method is wrapped by SourceFileName property, I think it says it tries to validate the file.

Quote from: Arx docs AcDbRasterImageDef::setSourceFileName
This function sets the pathname of the externally referenced image file. If the image was previously embedded (see AcDbRasterImageDef::embed), a call to this function removes the embedded image file from the current drawing. The image file path name is stored when the current drawing is next saved. The image definition is initialized and a file descriptor is created for access to the image file.

This function determines the actual file path (active file name) used for the current image definition is determined by a call to AcDbRasterImageDef::searchForActivePath().

Returns Acad::eOk if successful.

I'm not sure if that says internally it will call AcDbRasterImageDef::searchForActivePath() or recommends calling it.

Quote from: Arx docs AcDbRasterImageDef::searchForActivePath
This function searches the local drives and network for a valid image file that matches the source file name that is saved in the drawing file. This mechanism allows image files to be located differently on machines that are used for editing or viewing the same drawing file. Users can set up project search paths that contain directories in which image and xref files may be contained.

The search for a valid image file follows a specific order. First, the source file name (the path name set by setSourceFileName() and saved in the drawing) is checked as is. If it doesn't indicate a valid image file, then the file name is extracted from the path.

For example, a path of c:imagespicture1.bmp has the filename picture1.bmp. This file name is then searched for in each of a series of directories specified by the current project, followed by the standard AutoCAD paths.

 

The search order is as follows:

The source file name as specified by AcDbRasterImageDef::setSourceFileName().
The current project directories in order.
The current directory.
The directory that contains the current drawing file.
The directories named by the ACAD environment variable (if this variable has been specified).
The directory that contains the AutoCAD program files.
 

The first valid image file that is found will terminate the search. If the file extension is omitted from the file name, then all files with the same base file name (picture1, picture1.txt, picture1.exe, etc.) are also checked for validity as image files.

 

Returns the new active path if successful, or NULL otherwise.


latour_g

  • Newt
  • Posts: 184
Re: Modifying path of XREF image
« Reply #2 on: October 22, 2018, 10:40:41 AM »
Hi Jeff, thanks for your answer, it make sense !