Code Red > .NET

Something about Xref functions...

(1/11) > >>

LE:
I kept learning as I can all about this C# stuff, not much, but I am, at least trying.... he he

Here is a tryout to convert an attach xref to overlay - without luck of course, it is something I never tried on objectARX by the way... and also, there is no single sample anywhere (I think).


--- Code: ---[CommandMethod("ATOVERLAY")]
public void attachTooverlay()
{
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;
    //PromptEntityOptions prOpt = new PromptEntityOptions("\nSelect Xref: ");
    //prOpt.SetRejectMessage("\nNot an Xref!");
    //prOpt.AddAllowedClass(typeof(BlockReference), true);
    //PromptEntityResult rs = ed.GetEntity(prOpt);
    PromptEntityResult res = ed.GetEntity("\nSelect xref: ");
    if (res.Status != PromptStatus.OK) return;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockReference blkRef = tr.GetObject(res.ObjectId, OpenMode.ForWrite, false) as BlockReference;
        if (blkRef != null)
        {
            BlockTableRecord blkRec = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForWrite);
            if (blkRec.IsFromOverlayReference == false)
            {
                //db.DetachXref(blkRec.ObjectId);
                //db.ResolveXrefs(true, true);

                string fileName, blockName;
                fileName = blkRec.PathName;
                blockName = blkRec.Name;
                ed.WriteMessage("\nPath: " + fileName);
                ed.WriteMessage("\nBlockname: " + blockName);
                ObjectId xrefId = db.OverlayXref(fileName, blockName);
                if (xrefId.IsValid == true)
                    ed.WriteMessage("\nIs a valid object id...");
                else
                    ed.WriteMessage("\nNo valid object id...");

                db.ResolveXrefs(true, true);
            }
        }
        tr.Commit();
    }
}

--- End code ---

Since the OverlayXref() returns an ID.... what I should do with it?  or to make it work.... I tried first to detach the xref (it does that) but when I try to tun the overlay part... nothing.... nada.... niep.... nil

Thanks!

LE:
Here is my try using ARX and is working, still is a function in progress - mostly the undefined block message requires to get fix.... Will kept trying with the C# code...


--- Code: ---static void changeToOverlay (void)
{
ads_name ename;
ads_point pt;
AcDbObjectId xrefBlkId;
AcDbDatabase* pDb = NULL;
pDb = acdbHostApplicationServices()->workingDatabase();
if (acedEntSel(_T("\nSelect an Xref: "), ename, pt) != RTNORM) return;
if (acdbGetObjectId (xrefBlkId, ename) != Acad::eOk) return;
AcDbObjectPointer<AcDbBlockReference> pRef (xrefBlkId, AcDb::kForWrite);
if (pRef.openStatus() != Acad::eOk) return;
//acutPrintf(_T("\nBlockReference open..."));
AcDbBlockTableRecordPointer pBtr (pRef->blockTableRecord(), AcDb::kForWrite);
if (pBtr.openStatus() != Acad::eOk) return;
//acutPrintf(_T("\nBlockTableRecord open..."));

ACHAR *pFilename;
if (pBtr->pathName(pFilename) != Acad::eOk) return;
acutPrintf(_T("\nPath: %s"), pFilename);

ACHAR *pBlockName;
if (pBtr->getName (pBlockName) != Acad::eOk) return;
acutPrintf(_T("\nBlockname: %s"), pBlockName);

pBtr->close(); // no needed anymore

if (acedXrefDetach(pBlockName) != Acad::eOk) return;
acutPrintf(_T("\nDetaching block..."));

pRef->recordGraphicsModified();

if (acedXrefOverlay(pFilename, pBlockName) != Acad::eOk) return;
acutPrintf(_T("\nChanging to overlay..."));

pRef->recordGraphicsModified();
}

--- End code ---

T.Willey:
So the only way it to detach it, and reattach it as an overlay in both languages?  I was hoping that it would be some function that would just switch it.  I didn't see a way in C# when I looked, but was hoping you would find one Luis.  Thanks for keeping us posted.

LE:

--- Quote from: T.Willey on December 19, 2006, 04:49:51 PM ---So the only way it to detach it, and reattach it as an overlay in both languages?  I was hoping that it would be some function that would just switch it.  I didn't see a way in C# when I looked, but was hoping you would find one Luis.  Thanks for keeping us posted.

--- End quote ---

That's how I was able to make it work, but just the ARX code... the C# nope...

Alexander Rivilis:
P/Invoke? http://discussion.autodesk.com/thread.jspa?messageID=5206856

Navigation

[0] Message Index

[#] Next page

Go to full version