Column Location not updated after column creation

Column Location not updated after column creation

Anonymous
Not applicable
1,863 Views
7 Replies
Message 1 of 8

Column Location not updated after column creation

Anonymous
Not applicable

I've this strange situation:

I create a new structural column with this steps:

Step 1: creation

XYZ point = new Point(10, 0, 0);
FamilyInstance instance = document.Create.NewFamilyInstance(point, famSymbol, baseL, StructuralType.Column);

Step 2: rotation PI/4 = 90º from its own axis:

double rot = Math.PI/4;
XYZ vZ = new XYZ(0, 0, 1);
Location columnLocation = instance.Location;
LocationPoint pointLocation = columnLocation as LocationPoint;
if (pointLocation != null)
{
    Line axis = Line.CreateUnbound(pointLocation.Point, EjeZ);
    pointLocation.Rotate(axis, rot);
}

After this steps, the location point of the column is (0, 10, 0), not (10, 0, 0). Why?

Because after step 1, instance.Location.Point is the incorrect (0, 0, 0) instead of the correct (10, 0, 0) and, for a unknown reason, pointLocation.Rotate, rotates the column from its correct position (10, 0, 0) witth a a rotation axis positioned in the incorrect column position (0, 0, 0): the Location property is not returning the real location of the column!

 

I think this is an API error!

0 Likes
Accepted solutions (1)
1,864 Views
7 Replies
Replies (7)
Message 2 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous 

1)Because after step 1, instance.Location.Point is the incorrect (0, 0, 0) instead of the correct (10, 0, 0)???

Ans: When your transaction gets completed the columns are placed properly in the document. since you are getting the location point before placing the column you are getting the location point value as (0,0,0).

 

2)the Location property is not returning the real location of the column!

ans: after rotating your column commit the transaction and try to get the column position.so that you will get the new position of the column.

 

I tried your code and it is working properly for me.

 

try using the below suggestions.

1)start the transaction.

2)place the family instance.

3)commit the transaction

4)Get the location point of the column

5)start a new transaction

6)rotate the elements

7)commit the second transaction.

8)get the updated location point of the column

 

and one more point

rotation PI/4  is not "90 degree" it is "45 degree"

 

I hope this helps.,


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

Anonymous
Not applicable

Hello, naveen.kumar.t:

I've tried using SubTransactions and I'm afraid your suggestion doesn't work

This is my modified code

TransactionStatus subStatus = TransactionStatus.Uninitialized;
using (SubTransaction st = new SubTransaction(document))
{
    try
    {
        // create a new column
        subStatus = st.Start();
        FamilyInstance instance = document.Create.NewFamilyInstance(punto, famSymbol, baseL, StructuralType.Column);
subStatus = st.Commit(); // Rotation if (Math.Abs(rot) > .00001) { XYZ EjeZ = new XYZ(0, 0, 1); Location columnLocation = instance.Location; LocationPoint pointLocation = columnLocation as LocationPoint; if (pointLocation != null) { subStatus = st.Start(); Line axis = Line.CreateUnbound(pointLocation.Point, EjeZ); pointLocation.Rotate(axis, rot); subStatus = st.Commit(); } } return instance; } catch { if(subStatus == TransactionStatus.Started) st.RollBack(); return null; } } //SubTransaction

Of course, if I replace

Line axis = Line.CreateUnbound(pointLocation.Point, EjeZ);

with

Line axis = Line.CreateUnbound(punto, EjeZ);

it works fine, but that isn't my question.

 

Note 1: I've used SubTransactions instead of Transactions because I use this code with many elements and I want to group them in one Transaction

Note 2: You're rigth. PI = 180º, so 90º = PI/2

0 Likes
Message 4 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

Here is the complete code to place the column element and to rotate the column element.

I think the problem may be with your subtransaction.

After trying using the below code if you still get errors.....can you please explain your errors in detail?

//Start the TRANSACTION
                  Transaction actrans = new Transaction(doc);
                  actrans.Start("Single"); 

                //Start SubTransaction 1
                //Get the COLUMN element and place it in the document
                SubTransaction subT1 = new SubTransaction(doc);
                subT1.Start();
                FilteredElementCollector Collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Columns).OfClass(typeof(FamilySymbol)).WhereElementIsElementType();
                IList<Element> columns = Collector.ToElements() as IList<Element>;
                

                Element column = null;
                foreach(Element e in columns)
                {
                    if(e!=null)
                    {
                        column = e;
                        break;
                    }
                }

                FilteredElementCollector levelc = new FilteredElementCollector(doc).OfClass(typeof(Level));
                var ele = from Element in levelc where Element.Name == "Level 1" select Element;
                Level lev = ele.Cast<Level>().ElementAt<Level>(0);

                FamilySymbol Fs = column as FamilySymbol;
                XYZ loca = new XYZ(10, 0, 0);
                if(!Fs.IsActive)
                {
                    Fs.Activate();
                }

                //Place the column element
                FamilyInstance FI = doc.Create.NewFamilyInstance(loca, Fs, lev, StructuralType.Column);
               
                //Commit subtransaction 1
                subT1.Commit();


                //Start SUbTransaction 2
                //Rotate the column element
                SubTransaction subT2 = new SubTransaction(doc);
                subT2.Start();

                double rot = Math.PI / 4;
                XYZ vZ = new XYZ(0, 0, 1);
                Location columnLocation = FI.Location;
                LocationPoint pointLocation = columnLocation as LocationPoint;
                if (pointLocation != null)
                {
                    Line axis = Line.CreateUnbound(pointLocation.Point, vZ);
                    pointLocation.Rotate(axis, rot);
                }
                //Commit subTransaction 2
                subT2.Commit();

                //Commit the transaction
                actrans.Commit();

I hope this helps.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 8

Anonymous
Not applicable

Hi, 

 

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

The two first images were lost.

They are:

Before SubTransaction CommitBefore SubTransaction CommitAfter SubTransaction CommitAfter SubTransaction Commit

0 Likes
Message 7 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @Anonymous ,

Are you trying to set a parameter value for the column parameters?

As I mentioned earlier, you can set an instance parameter value for an element which is not placed in the project.

and your element is created in the project once the transaction gets completed.

I think sub transaction won't do that and you are confused between transaction and sub transaction.

First, understand the difference between transaction and sub-transaction.

https://thebuildingcoder.typepad.com/blog/2013/04/transactions-sub-transactions-and-transaction-groups.html

 

https://spiderinnet.typepad.com/blog/2012/05/revit-net-transaction-transaction-and-subtransaction.html

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-BECA30DB-23B4-4E71-BE24-DC4DD176E52D-htm.html

 

To put it in a simple way

1)First, start the transaction(not subtransaction)

2)place the family instance

3)commit the first transaction.

(once the transaction gets committed the element is created in the project)

4)start a new transaction(not subtransaction)

5)rotate the elements

6)set Instance parameter value for the placed elements 

7)commit the second transaction

(after the second transaction gets committed the parameters' values are changed and the elements are rotated )

This is the way to achieve what you want.

 

In your code

after the line 

Instance=document.create.NewfamilyInstance();

you should commit the transaction to create the element in the project.

since your element is not created or placed in the project you are getting the location point value as (0,0,0). 

after committing the transaction you will get the location point value.

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 8 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

HI @Anonymous 

In my previous post, I mentioned wrongly that

" you can set an instance parameter value for an element which is not placed in the project.

and your element is created in the project once the transaction gets completed."

 

actually, it is 

you can't set an instance parameter value for an element which is not placed in the project

and your element is created in the project once the transaction gets completed.

 

 

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network