Author Topic: Come one come all - Bind my xrefs  (Read 16387 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Come one come all - Bind my xrefs
« Reply #30 on: January 11, 2008, 12:12:29 PM »
I think that is how I would do it.
........ How would you do it?

I tried putting 3 sets of || in an IF and it worked, so I think Im going with that instead of SelectCase.
Next issue, if a bondhead, <cough> I mean drafter erased an xref instead of detaching, I need to try and fix that problem as well.  On to more studing
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Come one come all - Bind my xrefs
« Reply #31 on: January 11, 2008, 12:17:12 PM »
I think that is how I would do it.
........ How would you do it?
Sorry about that.  I would go with the || and if.

I tried putting 3 sets of || in an IF and it worked, so I think Im going with that instead of SelectCase.
Next issue, if a bondhead, <cough> I mean drafter erased an xref instead of detaching, I need to try and fix that problem as well.  On to more studing
If you want to make sure that an xref is inserted in the drawing, then you can check the length of the ObjectIdCollection returned by the method 'GetBlockReferenceId' of the BTR.  This will list all the ObjectId's of the blocks that reference the that particular BTR.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Come one come all - Bind my xrefs
« Reply #32 on: January 11, 2008, 12:44:04 PM »
ok, I tried this
Code: [Select]
                    if (string.Compare(XGN.Name.ToString(), "TEP", true) == 0 ||
                        string.Compare(XGN.Name.ToString(), "UES", true) == 0 ||
                        string.Compare(XGN.Name.ToString(), "VTEP", true) == 0 ||
                        string.Compare(XGN.Name.ToString(), "VUES", true) == 0)
                    {
                        BlockTableRecord BTR = Trans.GetObject(XGN.BlockTableRecordId, OpenMode.ForRead, false) as BlockTableRecord;
                        ObjectIdCollection OIC = new ObjectIdCollection();
                        OIC.Add(BTR.Id);
                        Db.BindXrefs(OIC, true);
                    }
and it works.  Is this better than the UCase?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Come one come all - Bind my xrefs
« Reply #33 on: January 11, 2008, 01:11:46 PM »
Why did you use the method ToString?  No need since the Name property (of the XrefGraphNode) returns a string.

Better than UCase..... not sure.  I guess in this case it wouldn't matter so much since you are providing one of the strings, and you know the case.

Why did you use == instead of .Equals?  I think that .Equals is the way to go, and I thought I heard about it from Tony T. here, but didn't find anything, but I did find this one a google search.

Found quote here.
Quote from: Joona I Palaste
== compares identity, equals() compares equality. Two object references
will only ever return true from == if they refer to the *EXACT* *SAME*
object. "Exact same" meaning there being only one object, with two
references referring to it. OTOH, equals() will return also true if the
references refer to two objects that are considered equal. The
consideration depends on the object class. It defaults to being the
same as ==. String overrides it by comparing the contents of the string.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Come one come all - Bind my xrefs
« Reply #34 on: January 11, 2008, 01:38:38 PM »
1. let me get back to you on that, I need to go see why
2. Because it worked, and I have never used .Equals(), I guess I should try that.

On to where I am so far, Im so close, I just cant figure out what I should be looking for
Code: [Select]
                    XrefGraphNode XGN = XG.GetXrefNode(i) as XrefGraphNode;
                    if (string.Compare(XGN.Name.ToString(), "TEP", true) == 0 ||
                        string.Compare(XGN.Name.ToString(), "UES", true) == 0 ||
                        string.Compare(XGN.Name.ToString(), "VTEP", true) == 0 ||
                        string.Compare(XGN.Name.ToString(), "VUES", true) == 0)
                    {
                        BlockTableRecord BTR = Trans.GetObject(XGN.BlockTableRecordId, OpenMode.ForRead, false) as BlockTableRecord;
                        ObjectIdCollection OIC = new ObjectIdCollection();
                        if (BTR.XrefStatus.ToString() == "Resolved")
                        {
                            //ObjectIdCollection OIC = new ObjectIdCollection();
                            OIC.Add(BTR.Id);
                            Db.BindXrefs(OIC, true);
                        }
                        else
                        {
                            Db.DetachXref(BTR.Id);
                        }

                    }

If you erase an Xref, it still evals to Resolved in the code
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Come one come all - Bind my xrefs
« Reply #35 on: January 11, 2008, 01:42:33 PM »
OK, I got rid of the ToString() and it still worked, so Im not sure why I had it
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8658
  • AKA Daniel
Re: Come one come all - Bind my xrefs
« Reply #36 on: January 11, 2008, 01:48:23 PM »

Why did you use == instead of .Equals?  I think that .Equals is the way to go, and I thought I heard about it from Tony T. here, but didn't find anything, but I did find this one a google search.


FYI sometimes the == operator and Equals() call the same  method to determine equality.
In the case of System.String the == operator calls Equals() which calls EqualsHelper().  :-)

Edit, Also have a looks at the StringComparer Class
http://msdn2.microsoft.com/en-us/library/system.stringcomparer.aspx

« Last Edit: January 11, 2008, 01:53:39 PM by Daniel »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Come one come all - Bind my xrefs
« Reply #37 on: January 11, 2008, 01:58:58 PM »
Thanks Daniel.

If you erase an Xref, it still evals to Resolved in the code
That is what I meant by checking the length of the ObjectIdCollection returned by the GetBlockReferenceIds method of the BTR.  So in your code you would do something like
Code: [Select]
                    XrefGraphNode XGN = XG.GetXrefNode(i) as XrefGraphNode;
                    if (string.Compare(XGN.Name.ToString(), "TEP", true) == 0 ||
                        string.Compare(XGN.Name.ToString(), "UES", true) == 0 ||
                        string.Compare(XGN.Name.ToString(), "VTEP", true) == 0 ||
                        string.Compare(XGN.Name.ToString(), "VUES", true) == 0)
                    {
                        BlockTableRecord BTR = Trans.GetObject(XGN.BlockTableRecordId, OpenMode.ForRead, false) as BlockTableRecord;
[color=red]                       ObjectIdCollection BlkRefCol = BTR.GetBlockReferenceIds(true, true);
                       if (BlkRefCol.Count > 0)
                       {
                                 // do what you want since the xref is inserted into the drawing.
                        }
                       else
                       {
                                 // do what you want since the xref is NOT inserted into the drawing.
                        }[/color]
                        ObjectIdCollection OIC = new ObjectIdCollection();
                        if (BTR.XrefStatus.ToString() == "Resolved")
                        {
                            //ObjectIdCollection OIC = new ObjectIdCollection();
                            OIC.Add(BTR.Id);
                            Db.BindXrefs(OIC, true);
                        }
                        else
                        {
                            Db.DetachXref(BTR.Id);
                        }

                    }
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Come one come all - Bind my xrefs
« Reply #38 on: January 11, 2008, 01:59:13 PM »
Daniel, that was so far over my head.....  but thanks for the headspin

TW, its time for a Duhism question:  If I had an xref, I erased it, I attached a new one, wouldn't the BlkRef.Count be >0? Or am I just missing the boat completely
« Last Edit: January 11, 2008, 02:03:42 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Come one come all - Bind my xrefs
« Reply #39 on: January 11, 2008, 02:14:33 PM »
TW, I got it!  that Rocks. :lol: :lol: :lol:
So we are looking for instances of the block
« Last Edit: January 11, 2008, 02:26:37 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Come one come all - Bind my xrefs
« Reply #40 on: January 11, 2008, 02:27:56 PM »
 :-)

Good to hear!
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Come one come all - Bind my xrefs
« Reply #41 on: January 11, 2008, 03:20:19 PM »
I really hate to ask this, but I cant find it anywhere.  How the heck do you save a dwg file thru .Net?  Not Saveas, I can find tons of examples of that.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Come one come all - Bind my xrefs
« Reply #42 on: January 11, 2008, 03:24:03 PM »
I really hate to ask this, but I cant find it anywhere.  How the heck do you save a dwg file thru .Net?  Not Saveas, I can find tons of examples of that.
You can't do a Save, only a SaveAs to the same name.

Quote from: Tony T. @ Ad Ng
Tim - It's not a bug.

You can't save a database to the same file it was read from, because it may not have been completely read in initially, so saving to the same file poses the risk of concurrently reading/writing to the same file.

The SAVE command uses saveAs() to save to a different (e.g., temporary) file and then either deletes or renames the original to *.bak, and then renames the saved file to the original filename.

Quote from: LE @ Ad Ng
After reading Tony description, I went and read about AcDbDatabase Class in
the ARX help - for the first time.

AcDbDatabase::save Function
Acad::ErrorStatus
save();
Currently not implemented. <<<=
From this recent thread.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Come one come all - Bind my xrefs
« Reply #43 on: January 11, 2008, 03:40:44 PM »
OK, I guess I should visit the A.NG more often.  I just dont like the peeps there, so I avoid it.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Come one come all - Bind my xrefs
« Reply #44 on: January 11, 2008, 03:44:22 PM »
OK, I guess I should visit the A.NG more often.  I just dont like the peeps there, so I avoid it.

There are knowledgeable people both here and there, so I post here, but look there also.   :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.