Revit API Editing Elements After Creation - c#

I have a questions that is more theory of "best practices" than actual technical programming.
I am trying to think of the best way to handle editing an element after it is placed by my program. Specifically I have my program set up as follows:
User clicks a tool that essentially "adds some families into a project" in Revit. It reads a sketch created by user and places items based on the sketch.
Sketch
Element creation
I want to give the user the ability to "edit the sketch" of those elements similar to say a floor slab. I don't believe the Revit API exposes the ability to sketch using "sketch mode". I am trying to mimic this very useful capability in my program.
So, what I have done is used extensible storage and store an UniqueId into all elements created using my tool. What the program does is when the user clicks "edit elements" tool, the program asks for the new sketch, asks to click on existing element, reads the UniqueId of the existing element and calls all elements with that UniqueId and deletes them, then the program adds new elements into the project again using the users "new sketch".
The problem is, if the user deletes the original elements that were added to the project and then tries to edit them, how do I guarantee the user is not going to delete those original elements that have the UniqueId? I think the way to go is to use the Dynamic Model Update functionality in the Revit API.
How are most of these algorithms written? Am I on the right track here? Do I just assign UniqueIds to elements and store them on the elements themselves so I can call them up later? Maybe there is a basic theoretical piece of the puzzle I am missing. Data structures?

I think you are essentially on the right track.
Using extensible storage to store the UniqueIds is definitely the way to go, and also using the DMU dynamic model updater functionality to react to changes sounds good.
The one thing that seems to be unclear is the fact the Revit will automatically assign the unique ids to the elements when they are created, and there is nothing you can do to affect that. The unique id is unique and immutable, and you have no control over it.
Therefore, the easiest approach is probably to delete all the previous sketch elements and recreate the entire sketch and all elements defining it from scratch whenever the sketch needs to be modified in any way.

You should use ElementId instead of UniqueId for structured storage, because an ElementId is automatically remapped to the new ElementId when a work sharing update occurs. The ElementId is also set To ElementId.InvalidElementId when the element is deleted.

Related

How to create a widget with a list of content parts in Orchard?

I'm working on a little Orchard CMS project and want to create a Widget to include in my Pages, from which I can add or remove items. Each of these items is a Product (small content part that displays a name, picture and short description for the item).
This Widget I want to create, should be able to add or delete products from it, without maximum or minimum limitations.
Then, how can I (in a programmatic way) create this content part that will have a collection (to put it in a way) of products?
I think the problem here is semantics. A widget in Orchard is a type and it is to be used embedded in Layers
You can easily do it programatically by attaching the a part (your widget) to any other ContentItem in the part's handler.
It can be done in Migrations too and if you check the latest version 1.9x, check the Layouts feature, using an Element (you can wrap your part in it) which seems to me would be the best choice here, since it gives you more control over which "pages" should contain these products.
In Layouts there is a Projection Element now, so that could help too.
There is always looking at the source. I have learnt lots from other people modules.

How can I copy HTML textbox values from one domain to another domain's textboxes?

I'm trying to help save time at work with for a lot of tedious copy/paste tasks we have.
So, we have a propitiatory CRM (with proper HTML ID's, etc for accessing elements) and I'd like to copy those vales from the CRM to textboxes on other web pages (outside of the CRM, so sites like Twitter, Facebook, Google, etc)
I'm aware browsers limit this for security and I'm open to anything, it can be a C#/C++ application, Adobe AIR, etc. We only use Firefox at work so even an extension would work. (We do have GreaseMonkey installed so if that's usable too, sweet).
So, any ideas on how to copy values from one web page to another? Ideally, I'm looking to click a button and have it auto-populate fields. If that button has to launch the web pages that need to be copied over to, that's fine.
Example: Copy customers Username from our CRM, paste it in Facebook's Username field when creating a new account.
UPDATE: To answer a user below, the HTML elements on each domain have specific HTML ID's. The data won't need to be manipulated or cleaned up, just a simple copy from ourCRM.com to facebook.com / twitter.com
Ruby Mechanize is a good bet for scraping the data. Then you can store it and post it however you please.
First, I'd suggest that you more clearly define exactly what it is you're looking to do. I read this as you're trying to take some unstructured data from Point A and copy it to Point B. Do the names of these fields remain constant every time you do the operation? Do you need to simply pull any textbox elements from the page and copy them all over? Do some sort of filtering of this data before writing it over?
Once you've got a clear idea of the requirements, if you go the C# route, I'd use something like SimpleBrowser. Judging by the example on their Github page, you could give it the URL of the page you're looking to copy, then name each of the fields you're looking to obtain the value of, perhaps store these in an IDictionary, then open a new URL and copy those values back into the page (and submit the form).
Alternatively, if you don't know the names of the fields, perhaps there's a provided function in that or a similar project that will allow you to simply enumerate all the text fields on the page and retrieve the values for all of them. Then you'd simply apply some logic of your own to filter those options down to whatever is on the destination form.
SO we thought of an easier way to do this (in case anyone else runs into this issue).
1) From our CRM, we added a "Sign up for Facebook" button
2) The button opens a new window with GET variables in the URL
3) Use a greasemonkey script to read those GET variables and fill in textbox values
4) SUCCESS!
Simple, took about 10 minutes to get working. Thanks for you suggestions.

C# saving and loading all form elements?

I'm trying to design my C# winform application with a very generalized function to automatically go through all of the form elements and save their states/values in a text file so that I can load it later. I want it to be very generalized so that it'll be a cinch to reuse this code in future projects, as it wouldn't be heavily tied down to the specifics.
The form elements I want to save are text boxes, combo boxes, data grid views, list boxes and that's about it. I want to save their values and everything about them.
One way that I was going about it was to go through every possible form element and then detect eachs type, and then create the corresponding c# code to re-create its value ('tboxmine.value="blue elephant"'), and then writing the code to a file, so that I could load the code from the file and execute it using the CSCcompiler. My code so far doesn't seem to be working correctly and I'm having my doubts that this compiler is actually running the code inside my application (I think it's possibly creating a new thread?), and it just seems like there's probably a far more straightforward relatively standard way of doing this.
This seems a bit like the reverse "best practice" approach. If you dont't know about databinding I suggest you look into that.
Basically you create classes to represent your data and use databinding to associate controls with your objects. The controls will automatically show the right value and allow the user to change it. If the user has changed the value, your object gets automatically updated.
To save the data, you would use some kind of serialization to store your objects in a file. When loading, you let the Serializer rebuilt your class structure and (best case) you are good to go.
This is not exactly what you asked for, but I think it is something you could use well ;-)
N.B.: Not the complete state of the control is saved. e.g. in a Textbox your text would be saved but the BackColor won't.
To get you started look into this tutorial: http://www.codeproject.com/Articles/24656/A-Detailed-Data-Binding-Tutorial

Static List and C#

I am building a Winform based C# desktop application. I have a number of Combox control which the user can select the input from the drop down list or manually enter an input. The Combox Items itself is populated from a static list.
Whenever the user enters a new input which is not present the list, I add to this static list.
Here is the small code snippet which does that :
if (!this.client_type.Items.Contains(items.ClientType))
{
ComboItems.ClientList.Add(temp.CourtName);
}
So far, this approach works as long as the application does not close or exit. When the application restarts, the list does not have the manually entered items.
I am considering saving the list in a configuration file. Is there any other approach apart from using a configuration file ?
Thanks
Any type of serialization should work. A couple of popular ideas:
Database: If you are already saving data to a database or if you want that same customized list to be available to all users regardless of if they are on the same machine then that may make the most sense.
XML: If the changes should be per box that it runs on then you would want to store it locally. XML is popular and there are libraries available in the framework to work with XML files.
Here is a link to look into other options.
Is there any other approach apart from using a configuration file?
Yes. (For example, a database.)
You might also take into consideration writing and loading the items list into the registry. Here is a link containing a nice tutorial on it's manipulation: http://www.codeproject.com/Articles/3389/Read-write-and-delete-from-registry-with-C

Custom PropertyGridEditor etc. for web part edit zone?

I want to change the appearance of the default editor parts, and am a little unsure of how to go about doing this, as there seems to be a surprising lack of documentation on the subject.
I've been able to create a custom declarative catalog with some trial and error and overriding the RenderCatalogPart method, and now wish to do something similar with my AppearanceEditor and PropertyGridEditor. I've tried just changing the style of the editor parts using CSS, but they are already arranged into tables which are impossible to get rid of. It's not even possible to just take the class as is, because the classes are sealed. So I'm basically stuck with having to write my own from scratch, I guess the questions are as follows:
1) How do I go about getting the information on the controls I need to render?
2) According to the documentation, I need to override the ApplyChagnes and SyncChanges methods - but I can't find any information on what I actually need to put in these methods.
3) On a similar note, is it possible to change the layout of the EditorPart itself, so that the AppearanceEditor, BehaviourEditor etc. are displayed side-by-side instead of on top of eachother?
4) Is there any way to have the page catalog displayed somewhere on the page, even in browse mode? I'd quite like to use it as a 'minimised' area, where users can send web parts they don't want immediately. At the moment they go back into the page catalog and users tend to just add a new part instead. I know that I can have multiple catalog zones on the page, which is great, but it only shows up in catalog mode.
Any help would be very much appreciated.
I didn't get any replies here, but I was able to figure out a way to do some of these.
In the end I decided to use reflection to get each public property on the web part that was WebBrowsable, and figure out what sort of control to display from the type.
The ApplyChanges() and SyncChanges() methods essentially just persist the changes from the page to the personalization blob and vice-versa. It's a matter of rendering some controls on the page, and mapping the values to the properties of the web part in these methods.
I don't think this is possible without writing your own.
Haven't been able to do this, but I don't imagine that it's possible sadly.

Categories

Resources