Plant3d: Get a Nipolet to connect

Plant3d: Get a Nipolet to connect

dennis
Advisor Advisor
853 Views
6 Replies
Message 1 of 7

Plant3d: Get a Nipolet to connect

dennis
Advisor
Advisor

After bringing in a PCF, I am finding that olets are not connecting up.  I have been studying this to correct, but haven't come up with the right combination.  I can manually toggle the nipolet to a sockolet, then back to a nipolet which does fix it up.  So my next direction to pursue is to try to imitate the toggle process via C#.  But I thought that I would post the question first for ideas.  Attached is a drawing with the issue.  Of course, you will need to add it to a Plant project to look it over properly.

 

dennis_0-1625139588791.png

 

0 Likes
Accepted solutions (1)
854 Views
6 Replies
Replies (6)
Message 2 of 7

jabowabo
Mentor
Mentor
Accepted solution

Have you considered using the PLANTCONNECTJOINT command?

ed.Command("_.PLANTCONNECTJOINT", part1Id, part2Id);

 

Message 3 of 7

dennis
Advisor
Advisor

*head thump*

So simple.  Too often I find myself planning the "hard way" rather than seeing the easy path.  Thanks again Jason, I do learn so much from you.

Message 4 of 7

dennis
Advisor
Advisor

Another catch.  At the time that I need it, the Editor.Command won't work cuz I am not in a Document environment.  So, I thought SendStringToExecute, which I believe will work for me if I can get the call string right.  However, it seems to choke on the ObjectIds that I want to send.  Everyway I try it, the ObjectIds end up being strings.  Any idea on this?  Or it can't be done that way?

0 Likes
Message 5 of 7

jabowabo
Mentor
Mentor

I assume you are using a control (button) on a modeless form like a toolpalette to run your command? If so, the easy way is to create a CommandMethod and set the button to call it something like this:

//button click
AcadApplication app = AcadApp.AcadApplication as AcadApplication;
app.ActiveDocument.SendCommand("mycommand\n");
[CommandMethod("Mycommand")]
public void Mycommand()
{
	// get part1Id and part2Id
	ed.Command("_.PLANTCONNECTJOINT", part1Id, part2Id);
}

 

0 Likes
Message 6 of 7

dennis
Advisor
Advisor

I actually group some commands like ZOOM Extents and QSAVE in the end of my routine.  So I wanted to add to my list of Commands to run to include the PLANTCONNECTJOINT and feed it the two ObjectIds that I already have.  I did try:

        const string TESTPLANTCONNECTJOINTname = "TESTPLANTCONNECTJOINT";
        [CommandMethod(TESTPLANTCONNECTJOINTname)]
        public static void RunTESTPLANTCONNECTJOINT()
        {
            var acDoc = acApp.DocumentManager.MdiActiveDocument;
            var acDb = acDoc.Database;
            var acEd = acDoc.Editor;
            try
            {

                var peo = new PromptEntityOptions("\nSelect first Part");
                peo.SetRejectMessage("Object must be an Part");
                peo.AddAllowedClass(typeof(Part), false);
                var per = acEd.GetEntity(peo);
                if (per.Status != PromptStatus.OK) return;
                var id1 = per.ObjectId;
                peo = new PromptEntityOptions("\nSelect second Part");
                peo.SetRejectMessage("Object must be an Part");
                peo.AddAllowedClass(typeof(Part), false);
                per = acEd.GetEntity(peo);
                if (per.Status != PromptStatus.OK) return;
                var id2 = per.ObjectId;
                //
                acEd.Command("_.PLANTCONNECTJOINT", id1, id2);
            }
            catch (Autodesk.AutoCAD.Runtime.Exception aex)
            {
                acEd.WriteMessage("\n" + aex.Message);
            }
            catch (System.Exception ex)
            {
                acEd.WriteMessage("\n" + ex.Message);
            }
        }

 

Above works, but requires that I select (manual labor) the two parts.  I already have the two ObjectIds, so wanted to figure out the SendStringToExecute string, but I can't figure out how to pass the IDs.  They keep coming out as strings.  For example if I could SendStringToExecute the above CommandMethod with the IDs as arguments, then that would do it.

 

I will keep working some other ideas I have, but if you have an idea I would appreciate it.

0 Likes
Message 7 of 7

jabowabo
Mentor
Mentor

You could store the ids in public static properties so they could be accessed by the command method. You'd probably want to set them null when the command is done. Not sure this is the best way to achieve what you want in the big picture but should work.