Results 1 to 6 of 6

Thread: Windows Form Pass to Revit Command

  1. #1
    Member
    Join Date
    2007-08
    Posts
    38
    Login to Give a bone
    0

    Unhappy Windows Form Pass to Revit Command

    I've spent days trying to get a button on a Windows Form to call a function to open the shared parameters file. Looked through almost all of the Samples and have learned a lot, but I am missing something obvious. Maybe someone will know what it is. Any thoughts would be appreciated. Probably should have asked for ideas sooner.

    My Windows Form is initialized and data collected on the with Click.

    private void selectWalls_Click(object sender, EventArgs e)
    {
    SetWallParams();

    }

    public void SetWallParams()
    {

    // Routine enters ok, BUT with next declaration, fails.
    Autodesk.Revit.Application app = revitData.Application;
    // Revit gives an unhandled exception here. I have not declared properly, but where and how, because I have to now execute in Revit.

    // Never get here. If I make this separate ExternalCommand works fine, but want to call it from WindowsForm.

    Document doc = revitData.Application.ActiveDocument;

    // Wall Parameters file
    DefinitionFile dDWallParamsFile = LocWallParamsFile(app); // Need to pass Revit app here, hence declaration about.

    // This function works from here.
    if (null == dDWallParamsFile)
    {

    }

  2. #2
    100 Club
    Join Date
    2007-10
    Location
    Brisbane
    Posts
    138
    Login to Give a bone
    0

    Default Re: Windows Form Pass to Revit Command

    Not sure if I entirely get what you are doing but here's what I think you need to do:

    - Make the separate command like you said worked, you have to have that as its the entry point to the application.
    - In the execute method (main method) create a new instance of your form ie Form1 newForm = new Form1();
    newForm.ShowDialog();

    - The key point you are missing is that you need to give the Application object to your form. So in your Form1 (im just using that as its name) add a class variable Application _app;
    then in your constructor (public Form1()) change it to accept a Application object and then set the class variable

    public Form1(Application app){
    _app= app;
    }

    then you can change your Document doc to be = to _app.ActiveDocument;
    and then when you need to use Application use _app

    hope this makes sense, if not let me know

  3. #3
    Member
    Join Date
    2007-08
    Posts
    38
    Login to Give a bone
    0

    Default Re: Windows Form Pass to Revit Command

    Thank you so much. I'll try this approach.

  4. #4
    100 Club
    Join Date
    2004-09
    Posts
    104
    Login to Give a bone
    0

    Default Re: Windows Form Pass to Revit Command

    Thanks annl for asking the question and thanks Rod for your response.

    I was having the same problem and solved it within 20 minutes of reading the post.

  5. #5
    Woo! Hoo! my 1st post
    Join Date
    2009-08
    Posts
    1
    Login to Give a bone
    0

    Default Re: Windows Form Pass to Revit Command

    annl
    I'm trying to implement a windows form that collects information from a revit project, carefully read the sample code that you put, but I can not make it work, appreciate your help and guidance.

    Thanks

  6. #6
    Member
    Join Date
    2008-08
    Posts
    49
    Login to Give a bone
    0

    Default Re: Windows Form Pass to Revit Command

    What is your goal?

    Are you saying that you would like to have a users browse for a shared parameter file and then load the file they select as the shared parameter file for their revit application?

    It is a two step process. First step the options path to the path you would like to use for your shared parameter file, and then load the share parameter file.

    Code:
             App.Options.SharedParametersFilename = filePath;
             try
             {
                m_sharedFile = App.OpenSharedParameterFile();
             }
             catch (System.Exception e)
             {
                MessageManager.MessageBuff.AppendLine(e.Message);
                return false;
             }
    Last edited by RobertB; 2009-09-30 at 05:52 PM. Reason: Added [code] tags

Similar Threads

  1. Pass vba selection set to lisp or command line?
    By KevinBarnett in forum VBA/COM Interop
    Replies: 11
    Last Post: 2019-02-15, 04:23 PM
  2. Windows form based stand alone application
    By pasxos867044 in forum VBA/COM Interop
    Replies: 4
    Last Post: 2012-09-21, 04:20 AM
  3. windows form
    By Alex5621314 in forum Revit - API
    Replies: 1
    Last Post: 2010-09-18, 02:06 AM
  4. AutoCAD file became slower to pass any command, how i can make it faster!
    By mohammed.asaduzzaman in forum Productstream - General
    Replies: 0
    Last Post: 2010-07-15, 06:00 AM
  5. Pass a list of points to Spline command
    By bowtle in forum AutoLISP
    Replies: 2
    Last Post: 2009-07-22, 09:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •