PostCommand

PostCommand

Anonymous
Not applicable
2,834 Views
14 Replies
Message 1 of 15

PostCommand

Anonymous
Not applicable

Hi,

 

I am using the following code:

 

RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.PlaceAComponent);

bool b = uiapp.CanPostCommand(commandId); // returns true
uiapp.PostCommand(commandId);

 

but it always places furbiture-desk. Can please anybody help me out in placing a group.

 

Thanks & Regards

Sanjay Pandey

0 Likes
Accepted solutions (1)
2,835 Views
14 Replies
Replies (14)
Message 2 of 15

Mustafa.Salaheldin
Collaborator
Collaborator

What do you want to do in first place?


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 3 of 15

RevitArkitek
Enthusiast
Enthusiast

The API help says it will place based on a selected element type.  Try putting the GroupType into the UIDocument.Selection then call PostCommand

0 Likes
Message 4 of 15

Anonymous
Not applicable

I am trying to mimick group placement. Exactly the same way we place group manually

 

Thanks & Regards

Sanjay Pandey

0 Likes
Message 5 of 15

jeremytammik
Autodesk
Autodesk

You should probably not be trying to use PostCommand. 

 

Take a look at PromptForFamilyInstancePlacement instead.

 

There are lots of discussions on it in The Building Coder.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 15

Anonymous
Not applicable

Hi,

 

Thanks for your suggestion.

 

I tried your suggestion. I first placed the group and selected it and called the code:

 

ICollection<ElementId> eed = uidoc.Selection.GetElementIds();

uidoc.Selection.SetElementIds(eed);

RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.PlaceAComponent );
bool b = uiapp.CanPostCommand(commandId); // returns true
uiapp.PostCommand(commandId);

 

but it always places desk

 

 

 

placecompnent.png

 

 

Thanks & Regards

Sanjay Pandey

0 Likes
Message 7 of 15

Anonymous
Not applicable

Hi,

 

PromptForFamilyInstancePlacement does not work for group placement.

 

Thanks & Regards

Sanjay Pandey

0 Likes
Message 8 of 15

Anonymous
Not applicable

on further exploration I found PostableCommand.PlaceAComponent only works for family instances

 

Thanks & Regards

Sanjay Pandey

0 Likes
Message 9 of 15

RevitArkitek
Enthusiast
Enthusiast

I said the GroupType not a group instance.  Get the element ID of the GroupType and place that in selection.  This is the same as if you were looking at the properties of a group or family from the Project Browser.  I do not know if it will still work or not though.

0 Likes
Message 10 of 15

Anonymous
Not applicable

Hi,

 

Thanks for the support.But I am loosing hope now. I will depict the out come of the following code via screenshots:

 FilteredElementCollector collector = new FilteredElementCollector(Command.doc).OfClass((typeof(GroupType)));
           var groupTypes = from element in collector
                            where element.Name == "MICRO PAD OE 45"
                            select element;
           Element groupType = groupTypes.First();
           GroupType ty = (GroupType)groupType;
           ICollection<ElementId> eed = new Collection<ElementId>();
           eed.Add(ty.Id);
           uidoc.Selection.SetElementIds(eed);
           RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.PlaceAComponent);
           bool b = uiapp.CanPostCommand(commandId); // returns true
           uiapp.PostCommand(commandId);

 

gp1.png

 

 

OUTCOME OF THE CODE:

 

gp3.png

 

 

 

 

AS I Told you this works only with family Instances only. Also I have no clue why it picked up the desk to place.

 

 

Thanks & Regards

Sanjay Pandey

 

 

0 Likes
Message 11 of 15

Mustafa.Salaheldin
Collaborator
Collaborator
Accepted solution

Oh god don't you ever lose hope Smiley Very Happy

 

Here is the solution

        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
        {
            _cachedCmdData = cmdData;

            try
            {
                //TODO: add your code below.
                FilteredElementCollector collector = new FilteredElementCollector(cmdData.Application.ActiveUIDocument.Document).OfClass((typeof(GroupType)));
                var groupTypes = from element in collector
                                 where element.Name == "MICRO PAD OE 45"
                                 select element;
                Element groupType = groupTypes.First();
                GroupType ty = (GroupType)groupType;

                cmdData.Application.ActiveUIDocument.PostRequestForElementTypePlacement (ty); //for revit 2015 and later

                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
                return Result.Failed;
            }
        }

 

If this statisfies your needs, don't forget to mark this reply as an answer.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 12 of 15

Anonymous
Not applicable

WOW WOW WOW.

 

That worked like charm. Thanks a Ton.

 

Thanks & Regards

Sanjay pandey

0 Likes
Message 13 of 15

Mustafa.Salaheldin
Collaborator
Collaborator

Good to hear that.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 14 of 15

Anonymous
Not applicable
I have already accepted your solution(marked as answer) along with a Kudo.
Thanks once again.
Message 15 of 15

jacsmithstrongtie
Contributor
Contributor

@Mustafa.Salaheldin Do you have any experience working with the PostableCommand.MirrorProject Post Command?  Also does what you shared with @Anonymous work from clicking a button in the ribbon or does the command you wrote for him generated automatically?  Sorry I am a new developer, and I am trying see if I can automate the Mirror Project feature in Revit 2024.