Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

PostCommand

Anonymous

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
Reply
Accepted solutions (1)
2,158 Views
14 Replies
Replies (14)

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

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

Anonymous
Not applicable

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

 

Thanks & Regards

Sanjay Pandey

0 Likes

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

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

Anonymous
Not applicable

Hi,

 

PromptForFamilyInstancePlacement does not work for group placement.

 

Thanks & Regards

Sanjay Pandey

0 Likes

Anonymous
Not applicable

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

 

Thanks & Regards

Sanjay Pandey

0 Likes

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

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

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

Anonymous
Not applicable

WOW WOW WOW.

 

That worked like charm. Thanks a Ton.

 

Thanks & Regards

Sanjay pandey

0 Likes

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

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

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.