How to place a family instance on a face of another family instance

How to place a family instance on a face of another family instance

an_vuong.nguyen
Contributor Contributor
5,854 Views
18 Replies
Message 1 of 19

How to place a family instance on a face of another family instance

an_vuong.nguyen
Contributor
Contributor

Hi everyone,

I was trying to find any similar post, but could not find any.

I'm trying to place a family instance on a face of another family instance. Does anyone have solution for that problem? Normally i use method Create.NewFamilyInstance for creating new family instance and placing it on a face reference via family symbol. But I just want to create a method for placing a family instance on a face(not placing a family symbol on face)


Thank you all very much

Cheers

An Vuong

0 Likes
Accepted solutions (1)
5,855 Views
18 Replies
Replies (18)
Message 2 of 19

franciscopossetto
Advocate
Advocate
Accepted solution

Hey

 

There are a couple of overloading options for the method you mentioned. Which you should choose might depend on the family you are going to insert. is your Family a line-based or it is just a family with a Location point? I have used those methods and always got a good result. The tricky part was getting the faces the logic needs. A good strategy could be to select the face of the FamilyInstance via UI Selection. In that case, you don´t have a face, you have a Reference. If you want a face as an argument, you can use the one that asks for a face as a first argument. I think you already saw them, but just in case I share them with you:

 

With a face as an argument:

https://www.revitapidocs.com/2022/3afcdf82-b25c-3092-d42c-b60490075d22.htm

 

With a reference as an argument (this one is the one you used):

https://www.revitapidocs.com/2022/be4b822c-829a-7e7b-8c03-a3a324bfb75b.htm

 

I hope it helps,

Kind regards

Github:
https://github.com/franpossetto
0 Likes
Message 3 of 19

an_vuong.nguyen
Contributor
Contributor

Hi @franciscopossetto ,

 

Thank you very much for your reply. That family is my own created family. This family has many different small elements inside. Two of them are location points. With yours methods i just can place a family symbol on a face. But i actually want to place a family instance on that face. Because when i used family symbol, i had a wrong beginning insertion point that is the first location point (called location point on the right side). And i cannot change this insertion point by editing family. I'm not allow to do it. So i would like to use the location point on the left side. Do you have any idea for that? 

 

Kind regards

0 Likes
Message 4 of 19

franciscopossetto
Advocate
Advocate

Hey,

 

Maybe I am not understanding correctly. When you say "Insert a Family Symbol" what do you mean? All those methods create new instances. So you should be able to do it in the same way.

 

FamilySymbol represents a Type:

https://www.revitapidocs.com/2022/a1acaed0-6a62-4c1d-94f5-4e27ce0923d3.htm

 

So you cannot insert a FamilySymbol as you insert an instance, because they don´t have geometry.

 

Could you upload an image?

Kind regards.

Github:
https://github.com/franpossetto
0 Likes
Message 5 of 19

an_vuong.nguyen
Contributor
Contributor

Hi,

 

Normally when you use Create.NewFamilyInstance, you need to have a family symbol. After creating this family symbol you can place it on a face. What i want is a similar method like NewFamilyIntance but with Family Instance as parameter, instead of family symbol as parameter. For example: 

 

public FamilyInstance NewFamilyInstance(
Face face,
XYZ location,
XYZ referenceDirection,
FamilyInstance instance
)

 

I'm not sure if that makes sense to solve my problem. I upload some images for you to understand my problem.

 

an_vuongnguyen_0-1630661837291.png

 

Tell me if you understand or not my problem. I'll try to explain again.

 

Kind regards

0 Likes
Message 6 of 19

franciscopossetto
Advocate
Advocate

Hey,

 

You are using a FamilySymbol as a parameter because it represents the type of instance that is to be inserted. Why would you need an Instance as a parameter to create a new Instance? 

 

Now with the image, I think I understood what you want to achieve. You have 2 references for your family and you want to insert an instance on the face where the red one is. Is it correct?

 

if so, How are you doing that? Could you share your code?

 

Github:
https://github.com/franpossetto
0 Likes
Message 7 of 19

an_vuong.nguyen
Contributor
Contributor

Hi,

 

When i use instance, i can place the left location point on red location point. With family symbol i just can place  the right location point on that red location point. And i cannot change this beginning insertion point by editing family. 

 

Yes that is correct. I placed an family instance on plane. Then i would like to create another family instance that is placed on the red location point. But the right location point was used while placing. I want to use the left location point. Sorry i cannot share the source code of my company. But i can give you a simple example similar.

 

document.Create.NewFamilyInstance(refFace, position, direction, famSym)

 

-refFace: is the red location

-position and direction are the position and direction i want to place refFace.

-famSym is the family symbol that was filtered from document.

 

 

0 Likes
Message 8 of 19

franciscopossetto
Advocate
Advocate

Hey,

 

Ok, so what you want to do is to choose the location point of your family (the right or the left) correct?

Sorry, it is a bit confusing for me yet.

Github:
https://github.com/franpossetto
0 Likes
Message 9 of 19

an_vuong.nguyen
Contributor
Contributor

i want to choose the left. No problem. It's also a litte bit difficult for me to describe that 🙂

0 Likes
Message 10 of 19

franciscopossetto
Advocate
Advocate

Ok. In the case the API doesn´t allow you to choose the point you want to use, I think you could do it by modifying a little Family Type. You might set a Type that mirrors the family or something like that. Instead of change the insertion point, you apply some logic to the family.

 

Good luck with that!

Github:
https://github.com/franpossetto
0 Likes
Message 11 of 19

an_vuong.nguyen
Contributor
Contributor

I think i cannot edit family. I am not allowed to do that. Can you explain more detail about logic you say. Or can you give a simple example? 

 

Thank you

0 Likes
Message 12 of 19

franciscopossetto
Advocate
Advocate

Yes for sure.

 

Assuming your family is a box, you might have just 1 insertion point and set a parameter to manage the position/rotation. You might rotate the element 180º if a parameter, (let´s suppose rotateParameter) is true.

After adding the Instance, you set the parameter as true or false, depending on if you want to rotate the instance or not. Rotate, in this case, as we are speaking about a box, does not change the result too much. Depending on the direction, it looks like you are placing your family from the left or the right. It depends on what you need. The logic could be completely different.

Github:
https://github.com/franpossetto
0 Likes
Message 13 of 19

an_vuong.nguyen
Contributor
Contributor

Hi,

 

Thank you for you explaining. I'm trying to implement like you say. 

0 Likes
Message 14 of 19

an_vuong.nguyen
Contributor
Contributor

Hi,

 

Sorry but i faced another problem. When i try to change coordinate of  a selected element, i cannot change z coordinate. Z coordinate is always 0. Here is my code.

 

LocationPoint locPoint = ele.Location as LocationPoint;

XYZ position = locPoint.Point;

XYZ newPosition = new XYZ(position.X + 18, position.Y, position.Z -6);

locPoint.Point = newPosition;

 

The x and y coordinates were changed. But z is always still 0. Do you know why? thank you very much.

 

Kind regards

0 Likes
Message 15 of 19

franciscopossetto
Advocate
Advocate

Hey,

 

The code seems correct. Are you able to perform this action manually? make sure you don´t have any restrictions related to the host.  If your family is hosted on a face, normally you just can move the family on this plane, thus leaving many other directions you cannot move. Also, check if the Z-axis is not being managed by another parameter. Ex: Walls with Base Constraint.

What are the Category and the templated you used to create this family?

 

Kind regards.

Github:
https://github.com/franpossetto
0 Likes
Message 16 of 19

hakansupurkeci
Enthusiast
Enthusiast

Hi,

If the product has a connector, you can plug it in using the origin of the connectors.

0 Likes
Message 17 of 19

an_vuong.nguyen
Contributor
Contributor
Sr for my late answer. I found a solution for my problem. I used Create.NewFamilyInstance(Reference ref, DB.XYZ location, DB.XYZ.referenceDirection, DB.FamilySymbol symbol). But i'm facing to another problem now. If i used this method to place an family instance on a face of another family instance, these two instances will be sticked together when i am trying moving them. Do you know any solution to separate them or divide them from each other?

Thank you very much
0 Likes
Message 18 of 19

hakansupurkeci
Enthusiast
Enthusiast

Hi,

 

I understand that you want to separate the two "instances" connected by "connectors".

 

Is it correct?

0 Likes
Message 19 of 19

hakansupurkeci
Enthusiast
Enthusiast

@an_vuong.nguyen 

Transaction trans = new Transaction(doc,"tra");
trans.Start();
try
{
ConnectorSet duct_connectorSet1 = GetConnectors(instance);
ConnectorSet duct_connectorSet2 = GetConnectors(instance_);
Connector connector1 = null;
Connector connector2 = null;
double minDist = double.MaxValue;
foreach (Connector conn1 in duct_connectorSet1)
{
foreach (Connector conn2 in duct_connectorSet2)
{
double distance = conn1.Origin.DistanceTo(conn2.Origin);
if (distance < minDist)
{
connector1 = conn1;
connector2 = conn2;
minDist = distance;
}
}
}
try{connector1.DisconnectFrom(connector2);}
catch(Exception ex) { MessageBox.Show(ex.ToString()); }
trans.Commit();

 

If I understood correctly, this method will work for you.

0 Likes