How to create temporary element?

How to create temporary element?

Anonymous
Not applicable
1,515 Views
5 Replies
Message 1 of 6

How to create temporary element?

Anonymous
Not applicable

I am trying to get the bounding box of a familyinstance that is created inside a transcation and use it to adjust its parameter in a single transaction. Here is the code.

 

using (Transaction t = new Transaction(doc, "Create Multiple"))
            {
                t.Start();
                foreach (View view in views)
                {
                    FamilyInstance fi = doc.Create.NewFamilyInstance(point, symbol, view);
                    BoundingBoxXYZ b = fi.get_BoundingBox(doc.ActiveView);
                    fi.LookupParameter(param).Set(b.Max.X.ToString());
                }
                t.Commit();
            }
0 Likes
1,516 Views
5 Replies
Replies (5)
Message 2 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

you can't set the value of instance parameter before creating the family instance in the project.

Instance parameters are accessible only after creating a family instance inside the project.

Your family instance is created only after the transaction gets completed.

To set the value for a parameter, create one more transaction and set the value.

 

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 6

Anonymous
Not applicable

How do I create another transaction inside a loop and assimilate it in a single transaction to make it undoable once.  I am still new in creating subtransactions.

0 Likes
Message 4 of 6

Anonymous
Not applicable

Got it to work. I thought that the error was in my Subtransaction.

Message 5 of 6

ottosson_mathias
Advocate
Advocate

@AnonymousI'm having the same question. Can you share your solution?

 

Thanks!

0 Likes
Message 6 of 6

LTusche1
Participant
Participant

Look into TransactionGroups, any transaction that you start and commit within a TransactionGroup, can be rolled back via TransactionGroup.RollBack.

 

1: Start a TransactionGroup

2: Start regular Transaction

3: Create your element
4: Commit regular Transaction

5: Start another regular Transaction

6: Change parameters

7: Commit regular Transaction

8: Get BoundingBox of your element

9: Rollback the TransactionGroup

 

Hope this helps.

0 Likes