Getting parameters assigned to a label

Getting parameters assigned to a label

CADdaddy.com
Collaborator Collaborator
3,531 Views
17 Replies
Message 1 of 18

Getting parameters assigned to a label

CADdaddy.com
Collaborator
Collaborator
 

Hi All,

 

I'm interested in getting a list of all the parameter names associated with a label. I'm able to get the labels.  I'm able to get the parameters OF the label.  I've scoured Revit Lookup but can't seem to find the parameters ASSIGNED to the label. 

 

I don't even need the actual parameters, just the parameter name strings, "Detail Number" etc.

 

Seems like it should be easy...

 

image.png

 

Regards,

 

James

0 Likes
Accepted solutions (1)
3,532 Views
17 Replies
Replies (17)
Message 2 of 18

jeremytammik
Autodesk
Autodesk

If you have access to the Parameter itself, i.e., the object residing on the Revit Element and containing the parameter value, that you can easily access its name or label as well. It is defined by the parameter Definition object, accessible via the Parameter.Definition property:

  

https://www.revitapidocs.com/2020/dc30c65f-cfc4-244e-5a5c-bc333d7cd4c5.htm

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 18

CADdaddy.com
Collaborator
Collaborator

Hi Jeremy,

 

Thanks for the prompt reply!   

 

The problem is that I can't get (or don't know how to get) the actual parameter object.  In Revit Lookup, following the Label parameter of the TextElement leads to what appears to be a dead end.

 

image.png

0 Likes
Message 4 of 18

RPTHOMAS108
Mentor
Mentor

As far as I know this is still not possible. I've long ago categorised it under 'you'd think it would be easy but is actually impossible.'

 

I believe the SharedParameterElement objects you get in a family are typically those used as parameters and not necessarily those used in a label. 

0 Likes
Message 5 of 18

jeremytammik
Autodesk
Autodesk

Wow. Shocking. I certainly hope a wish has been raised for this in the Revit Idea Station, at least.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 18

RPTHOMAS108
Mentor
Mentor

Hello Jeremy,

 

Yes it is surprising. I've added an Idea for it now within the link below, hope the idea is clear enough.

 

https://forums.autodesk.com/t5/revit-ideas/list-parameters-used-in-a-label-textelement-within-a-fami...

 

At one point this was definitely an item at the top of my list but my priorities changed.

Message 7 of 18

matthew_taylor
Advisor
Advisor

Hi @RPTHOMAS108 

Thanks for creating the idea! I came up against this a long while back.

Hi @CADdaddy.com 

The thought that reading these latest posts brought up was that there's a possible (terrible!) workaround.

Create a dud model, create an instance of the thing to be tagged, tag it with your family, set the parameters of the instance to unique values, then read the tag's TagText value, and decipher it.

 

I told you it was terrible.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 8 of 18

CADdaddy.com
Collaborator
Collaborator

Thank you for the confirmation.  Now I can quit wondering if I've missed something.

 

Is there any other way to do the following:

 

My goal is to determine programmatically whether a viewport is currently displaying the drawing number on the sheet.  Is there any other way to confirm that besides checking to labels in the family to see if one contains a pointer to the DrawingNumber parameter?

 

james

 

 

 

0 Likes
Message 9 of 18

CADdaddy.com
Collaborator
Collaborator

Okay....in the time it took to write may last post there've been suggestions!  Not so terrible ones!  They can work since there are usually only a couple of view title families in a project so performance won't be an issue.

 

I'll let you know how it goes.  Thanks

Message 10 of 18

matthew_taylor
Advisor
Advisor
Accepted solution

@CADdaddy.com ,

Your description helped me a little more. I don't think my 'terrible' idea will work as you are not dealing with an IndependentTag.

The solution may be easier though.

  1. Get the viewport. From that, use GetLabelOutline to get the size of the title.
  2. Renumber the referenced sheet number so that its number is very long.
  3. Commit transaction (or regenerate?).
  4. Check GetLabelOutline again to see if the size has changed. If so, it likely contains the referenced sheet number.
  5. Roll back the transaction.

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 11 of 18

james.levieux
Advocate
Advocate

Wow, Matthew, you are certainly the master of insane-but-tantalizingly-possible workarounds.  I'll give it a go!

0 Likes
Message 12 of 18

matthew_taylor
Advisor
Advisor

@james.levieux ,

Haha, thanks James.

The Revit API is vast, but sometimes not vast enough.

I can't take credit for inventing the temporary transaction trick, but there are many uses for it. 🙂

 

Let us know how you get on!


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 13 of 18

james.levieux
Advocate
Advocate

This works in preliminary tests.  Thanks a million.

 

private bool dwgNumVisibleOnSheet(Viewport viewport)
{ 
    //method to determine if drawing number is displayed by the viewport on the sheet.

    //This is needed in the case where the title is not hidden but, either the Drawing 
    //Title component family does NOT include a label that points to the
    //Detail Number parameter OR the label that points to the Detail
    //Number is HIDDEN in the type.

    //This method was written as a workaround because it appears to be 
    //impossible to acquire whether a label pointing to the Detail Number exists 
    //in a Drawing Title component family by  directly inspecting the contents
    //using doc.EditFamily.

    //get current size of label outline
    double curOutline = viewport.GetLabelOutline().GetDiagonalLength();

    //temporary transaction to acquire new size after changing the Detail Number 
    //to a large size that will (hopefully) certainly change the boundary no matter the size
    //of the view or the justification of the text
    Transaction trans = new Transaction(viewport.Document);
    trans.Start("testingDrawingNumberVisible");
        Parameter vp = viewport.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER);
        string str100 = "----------------------------------------------------------------------------------------------------";
        vp.Set(str100 + "Revision Narrative Test String" + str100);
        viewport.Document.Regenerate();
        Double newOutline = viewport.GetLabelOutline().GetDiagonalLength();
    trans.RollBack();

    //compare sizes
    if (curOutline==newOutline) return false;
    return true;
}

 

Message 14 of 18

jeremytammik
Autodesk
Autodesk

Looking good to me... very creative approach.

 

Congratulations on solving such an unsolvable task!

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 15 of 18

matthew_taylor
Advisor
Advisor

Nice one @james.levieux! Glad you got it sorted; thanks for sharing your working.

You may also be able to make assumptions about other viewports based on their type. It may also be worth adding the existing detail number into the temporary string in case you want to check more than one (it may need to be unique?) in a loop.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 16 of 18

RPTHOMAS108
Mentor
Mentor

As an alternative suggestion:

 

In your company template you have:

1) A number of system family view ports defined each of which reference:

2) A single annotation symbol family from a limited set of annotation families loaded into your project or in your library external to the project.

3) Item (1) above also contains a built in type parameter named 'Show Title' (Yes/No/When Multiple Viewports)

 

So for each viewport you should know which (1) is set for it, which leads to which (2) is defined for that (1) along with what the parameter value of (3) is for (1). Therefore the visibility of the title parameter on a sheet can be known based on knowing your content.

 

If it isn't your content library then you create a settings mapping for a third party to indicate if a particular item from (2) above contains Sheet Number. We have around ten system families defined for viewport (ten yes/no's for contains Sheet Number). 

 

0 Likes
Message 17 of 18

CADdaddy.com
Collaborator
Collaborator

Hi Matt,

 

I can use the same test string every time because the value always gets rolled back before the next viewport is tested.  There will never be a duplication.  I should probably put it all in a try/catch statement to ensure it gets rolled back in the event of an unexpected error.

 

Definitely not air tight though.  Somebody could use a left justified Drawing Number label in a very wide viewport where the line is longer than my text string.  Also, needing to regen to check every viewport type could be a significant dragfor some projects.  I've seen a lot of firms who use a separate viewport type for every 1/2" of viewport width (they don't use the stretchy line).  That could be the deal breaker.

 

Regards,

James

0 Likes
Message 18 of 18

matthew_taylor
Advisor
Advisor

Hi James,

I think your air-tightness and performance issues can all be mitigated.

Do it all within one transaction, make the strings unique, and make your string longer...you need to allow for wordwrap too. (Adding spaces to the test string will help wordwrap; best to avoid them.)
Quasi-code in VB.NET:

dim currOutlineDict as new Dictionary(of Viewport, Double)

Using trans as new Transaction(doc,"Temp Trans")

trans.start

For each viewport as ViewPort in Viewports

  dim failViewports as new  list (of viewport)

  Dim curOutline =...

  currOutlineDict.Add(Viewport, curOutline)

  'Set viewport text here.

  dim str100  as string= "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" ' The letter W is wide. 😉
   vp.Set(str100 +viewport.Id.tostring() + str100)

next

doc.regenerate

For each viewport as ViewPort in Viewports

  Dim newOutline =...

  Dim currOutline= currOutlineDict.item(viewport)

  If currOutline = newOutline then 'Introduce FUZZ check here

    failViewports.add(viewport)

  end if

next

trans.rollback

end using

return failViewports


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?