Rehosting Adaptive Point

Rehosting Adaptive Point

tamas.deri
Advocate Advocate
2,500 Views
15 Replies
Message 1 of 16

Rehosting Adaptive Point

tamas.deri
Advocate
Advocate

I'm struggling with rehosting an adaptive point to a geometry, in my case it is a Model Line in a FamilyInstance. The main source of the problem that as some of us knows is getting geometry with references from FamilyInstances is kinda sketchy. I can get the Line in Project Coordinates from the `GeometryElement` got from `GeometryInstance.GetInstanceGeometry()`, however the Reference taken from this Line is in the Family's Coordinate System, and using this Reference as a host for the ReferencePoint moves my Adaptive Component to a completely wrong position.

It is also known, that if I use the Line from `GeometryElement` got from `GeometryInstance.GetSymbolGeometry()` returns the Reference in Project Coordinates (btw in this case the Line object itself will be in the Family's coordinates.... total nonsense). Using this reference for the `PointOnEdge' object for setting the `ReferencePoint`'s element reference with `.SetPointElementReference()` throws an `InternalException` without any interpretable explanation.

Because of the reasons above I've tried using the wrong reference for hosting the RefPoint, and later updating the Position of the Refpoint using the FamilyInstance's Transform, but this wasn't succesfull either, because the RefPoint sticks to the invisible, Family Coordinate System based Reference.

 

Any tips to solve this?

 

I've also made a video about how I fail to achieve my goal, please find it attached. 🙂

 

The code for reference:

 

 

adaptive_family = doc.GetElement(DB.ElementId(3787458))
line_family = doc.GetElement(DB.ElementId(3762716))
placementPointIds = DB.AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(adaptive_family)
placementPoints = [doc.GetElement(i) for i in placementPointIds]
curves = []
opts = DB.Options()
opts.ComputeReferences = True
gi = next((e for e in line_family.get_Geometry(opts) if isinstance(e, DB.GeometryInstance)), None)
tr = gi.Transform
curve_instance = next((e for e in gi.GetInstanceGeometry() if isinstance(e, DB.Curve)), None)
curve_symbol = next((e for e in gi.GetSymbolGeometry() if isinstance(e, DB.Curve)), None)
curve = curve_instance

with db.Transaction():
	for ap in placementPoints:
		#if placementPoints.index(ap) > 0: break
		ir = curve.Project(ap.Position)
		ploc = DB.PointLocationOnCurve(
			DB.PointOnCurveMeasurementType.NonNormalizedCurveParameter,
			ir.Parameter,
			DB.PointOnCurveMeasureFrom.Beginning
		)
		
		ref = curve_instance.Reference
		#ref = curve_symbol.Reference
		
		poe = doc.Application.Create.NewPointOnEdge(
			ref,
			ploc
		)
		ap.SetPointElementReference(poe)
		#ap.Position = tr.OfPoint(ap.Position)

 

 

0 Likes
Accepted solutions (1)
2,501 Views
15 Replies
Replies (15)
Message 2 of 16

tamas.deri
Advocate
Advocate

I've created a small testproject with a macro that shows the issue above. It is possible to rehost an adaptive component to a model line, if it lost its host, but it is not working if I want to rehost it to a model line in a famiy (which is possible manually via the UI, obviously). If I use the edge reference from the InstanceGeometry it messes up the coordinate systems, if I use the edge reference from the SymbolGeometry it throws an internal exception without any explanation.

@jeremy_tammik is there any chance to take a look at it? Perhaps forward this issue to the dev team if it is neccessary.

Thanks in advance!

0 Likes
Message 3 of 16

tamas.deri
Advocate
Advocate

I've managed to get more information about the InternalException

 

Autodesk.Revit.Exceptions.InternalException: A managed exception was thrown by Revit or by one of its external applications. a kovetkezo helyen: Autodesk.Revit.DB.PointOnEdge.apply(ADocumente A_O, ReferencePoint* A_1) a kovetkezo helyen: Autodesk.Revit.DB.ReferencePoint.SetPointElementReference(PointElementReference pointElementReference)

0 Likes
Message 4 of 16

tamas.deri
Advocate
Advocate

Another update:

I've also tried using the reference of the OOTB reference line that I got from calling FamilyInstance.GetReferences(), but it throws the same InternalException

0 Likes
Message 5 of 16

tamas.deri
Advocate
Advocate

Nevermind, I've found this:

https://forums.autodesk.com/t5/revit-api-forum/edge-reference-of-a-family-instance/m-p/7088651

So it is time to do some unjustified geometry joining stuff...

0 Likes
Message 6 of 16

tamas.deri
Advocate
Advocate

Okay this seems like I'm talking to myself, but this is definately an issue / bug in the internals of Revit API, because I can't even rehost the adaptive point to the very same edge where it was hosted on previously by hand.

 

IronPython 2.7.7 (2.7.7.0) on .NET 4.0.30319.42000 (64-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> e = selection[0]
>>> placementPointIds = DB.AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(e)
>>> placementPoints = [doc.GetElement(i) for i in placementPointIds]
>>> pt = placementPoints[0]
>>> poe = pt.GetPointElementReference()
>>> poe
<Autodesk.Revit.DB.PointOnEdge object at 0x0000000000002E33 [Autodesk.Revit.DB.PointOnEdge]>
>>> with db.Transaction():
... 	pt.SetPointElementReference(poe)
... 
[ERROR] Error in Transaction Context: has rolled back.
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
Exception: A managed exception was thrown by Revit or by one of its external applications.

>>> 

 

 Although it is possible to make it work using sketchy workarounds in a laboratory like environment with very strict boundary conditions like joining and unjoining certain elements, etc, but it is definately a thing that needs to be fixed. Since I don't know about a specific way of posting bug reports, I call this thread one.

Hope it will be fixed some day.

0 Likes
Message 7 of 16

jeremy_tammik
Alumni
Alumni

Sorry for not jumping in and replying faster. I really did not know what to say. However, internal exceptions should never be visible to an external add-in, so this is definitely something for the development team to take a look at. I will prepare a case to submit to them asap.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 8 of 16

tamas.deri
Advocate
Advocate

Thank you very much for that!

0 Likes
Message 9 of 16

jeremy_tammik
Alumni
Alumni

Dear Tamas,

 

Thank you for your report, clear description and sample material.

 

Sorry to hear about this.

 

I logged the issue REVIT-181722 [API Rehosting Adaptive Point throws InternalException] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 10 of 16

tamas.deri
Advocate
Advocate

Dear Jeremy!

Please find the required information below:

  • Impact on your application and/or your development.
    This defect makes our efforts to provide a user friendly alternative to the built-in railing tool for in-house design teams superfluous, because there is no known workaround for this issue, thus achieving the goal is impossible.
  • The number of users affected.
    ~ 100
  • The potential revenue impact to you.
    Measurable man-hours.
  • The potential revenue impact to Autodesk.
    Can not tell. At the end of the day it is a bug-fix so...
  • Realistic timescale over which a fix would help you.
    The sooner the better.
0 Likes
Message 11 of 16

jeremy_tammik
Alumni
Alumni

Thank you, added to the ticket.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 12 of 16

jeremy_tammik
Alumni
Alumni

Dear Tamás,

 

Thank you for your patience.

 

The development team analysed and confirmed the issue you reported.

  

They closed the initial ticket REVIT-181722 [API Rehosting Adaptive Point throws InternalException] as code fix needed and opened a new ticket REVIT-181785 [API Rehosting Adaptive Point throws InternalException] to perform the actual development work.

 

Please make a note of this number as well for future reference.

  

Best regards,

 

Jeremy

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 13 of 16

tamas.deri
Advocate
Advocate

That's great news,  thank you!

0 Likes
Message 14 of 16

tamas.deri
Advocate
Advocate

Hi @jeremy_tammik , are there any updates on ticket REVIT-181785 ?

0 Likes
Message 15 of 16

jeremy_tammik
Alumni
Alumni
Accepted solution

Dear Tamás,

 

Thank you for your update and interest.

 

Good news:

 

The development team closed the ticket REVIT-181785 [API Rehosting Adaptive Point throws InternalException] with resolution 'Fixed' and fix versions Revit 2022.1.4, update release Revit 2023.1 and the future major release after Revit 2023.

 

As always, we make no promises whatsoever about future releases, but we can always hope that things work out as planned.

 

Best regards,

 

Jeremy

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 16 of 16

tamas.deri
Advocate
Advocate
Thats great news, thank you! Looking forward to give it a try!
0 Likes