'...' is not an attribute class . Error cs0616 c#

'...' is not an attribute class . Error cs0616 c#

mr.engineer.aec
Advocate Advocate
4,615 Views
5 Replies
Message 1 of 6

'...' is not an attribute class . Error cs0616 c#

mr.engineer.aec
Advocate
Advocate

 Hi guy,

 

 I'm newbie in Revit Macro. I am learning about Revit API & Macro.
 I want to visible rebar as solid in 3D view, I search code from this topic: 
https://forums.autodesk.com/t5/revit-api-forum/set-solid-in-view-structural-rebar/td-p/7873124
 But when i build my code in SharpDevelop, error like this pic attached, what i can solve this error.

 

 Many thanks,

 My English is not good, Sorry for the inconvenience!


0 Likes
Accepted solutions (2)
4,616 Views
5 Replies
Replies (5)
Message 2 of 6

so-chong
Advocate
Advocate
Accepted solution

Hi,

Welcome to this forum.
What you are trying to do is implementing 'Standard Revit API' code (created with Microsoft Visual Studio) to 'Revit Macro API' environment (create macro in Sharpdevelop editor).
That definitely won't work.
There are some differences between these API you should be aware of, otherwise all code (snippets) on this forum make no sense to you how to migrate the code to your Revit macro IDE.
I have found some useful links you might be interested;

 

general use of the macro manager and the Revit Macro IDE
https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2019/EN...

 

Revit API differences reference
http://help.autodesk.com/view/RVT/2019/ENU/?guid=GUID-C6E0196D-918B-4131-9B64-050DBE452158

 

example code from standard Revit API to Revit macro IDE
http://help.autodesk.com/view/RVT/2019/ENU/?guid=GUID-8870CDF7-A248-4423-9CB6-D2E2C62FC3DB

 

To give you an idea how this code could look like as a macro see inserted code

(i have also included the using directive 'Autodesk.Revit.DB.Structure;')

Copy and paste the code in your macro IDE, build solution and there should be no error displaying.

 

I hope this is useful for you and wish you good luck with your journey here with the Revit API.

 

Cheers,
So-Chong

 using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB.Structure;
using System.Collections.Generic;
using System.Linq;

namespace SetRebarSolid
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.DB.Macros.AddInId("69497BD4-FEC5-4FF7-87B7-D5696A5B0C5D")]
    public partial class ThisApplication
    {
        private void Module_Startup(object sender, EventArgs e)
        {

        }

        private void Module_Shutdown(object sender, EventArgs e)
        {

        }

        #region Revit Macros generated code
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(Module_Startup);
            this.Shutdown += new System.EventHandler(Module_Shutdown);
        }
        #endregion
        public void SetSolidRebar()
        {
            Document doc = this.ActiveUIDocument.Document;
               
            ICollection<Element> rebars = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Rebar).ToElements();
            List<Rebar> List_Rebar = new List<Rebar>();  
            if(rebars==null)
            {
                TaskDialog.Show("REBAR""NO REBAR EXISTS IN THE DRAWINGS");
            }
 
            using (Transaction trans = new Transaction(doc, "Set Solid Rebar"))
            {
                trans.Start();
                IEnumerable<ViewFamilyType> VFT = from Element in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)) let type = Element as ViewFamilyType where type.ViewFamily == ViewFamily.ThreeDimensional select type;
                View3D v3d = doc.ActiveView as View3D;
                foreach(Rebar r in rebars)
                {
                    r.SetSolidInView(v3d, true);
                    List_Rebar.Add(r);
                }
                TaskDialog.Show("LIST_REBAR", List_Rebar.Count().ToString());
                trans.Commit();
            }
        }
    }
}
Message 3 of 6

mr.engineer.aec
Advocate
Advocate

 @so-chong 
Thank you for talking trouble to help me.

This information are really useful for me.
I'll study about them.
I hope to receive your help if I have problems with Revit API & Macro.

 

Many thanks.

0 Likes
Message 4 of 6

mr.engineer.aec
Advocate
Advocate

Hi @so-chong

I used your code in Revit Macro but i receive an error message like pic attached.
Can you help me to solve this issue ?!
Thank you.

0 Likes
Message 5 of 6

so-chong
Advocate
Advocate
Accepted solution

 Hi,

 

This error occurs when code is written for an 'application' macro is used for 'document' macro.

When you start the macro manager you will find two tabs to choose from (upper left corner of the macro manger);

- left side is for application macro

- right side is for document macro

 

So, to run the macro as a document macro you have to replace this line of code

Document doc = this.ActiveUIDocument.Document;

with this

Document doc = this.Document;

Hope this helps.

Message 6 of 6

mr.engineer.aec
Advocate
Advocate

@so-chong

It worked.

I'm not coder. It's really hard for me without you to help me.

Thank you for talking trouble to help me.

0 Likes