C # implementing dynamic simulation for the secondary development of Visio

Source: Internet
Author: User

There are many project scenarios that can be implemented by the secondary development of Visio, such as electrical line analysis, distribution network analysis, and flowcharts. Now, due to the needs of the project, I know another application scenario and the simulation of hydraulic transmission. The project is as follows:

 

Dynamic simulation, in fact, is to simulate the trend of the actual line, to achieve the display of animation. In the past, my Visio projects were mostly based on static graphics, and there were not too many dynamic presentations. The analysis of the power-on lines in the original distribution network is strictly static, because the power-on and power-off lines are basically drawn at one time. Dynamic Simulation requires that the line direction and color change be slowly animated.

Such as the simulation of the piston movement, the animation can be continuously changed without stopping the animation. As shown in:

 

This article describes how to achieve line direction, color change, and Dynamic Simulation of specific graphics (such as pistons.

First, to achieve the dynamic simulation effect, we must first analyze the topological network sequence and layers of the entire drawing, so that we can know the correct line direction and the order of animation changes, such as in the distribution network circuit diagram, it must start from the power supply and transmit power through wires or equipment to achieve circuit connection. In the hydraulic line, the fuel tank starts, passes through a series of equipment, and finally returns to the fuel tank.

The most important secret of implementing an animation effect such as on a Visio drawing is to use the following code:

 

System. Windows. Forms. Application. DoEvents ();
Thread. Sleep (50 );

 

 

 

In many cases, we may not be very familiar with the functions of this DoEvents function. In fact, we can understand it as an active event trigger, allowing the message stream to enter the processing process in advance, in this way, we can see the graphic update effect on the Visio drawings.

The entire graph analysis process is divided into three steps:

1) perform a simple topology analysis to maintain the relationships around the device to the database for analysis.

2) analyze the device relationship based on the database structure to obtain the device hierarchy list of the topological network.

3) Draw and simulate the device based on the current status of different device types and drawings.

 

The rough code is as follows:

 

Private void PowerCutAnalyze (Visio. Application app)
{
# Region obtain the operating device and determine whether the drawing has a device
Visio. Shape shapeSelected = null;
Try
{
Visio. Window wndVisio = app. ActiveWindow;
If (wndVisio. Selection. Count = 1)
{
ShapeSelected = wndVisio. Selection. get_Item16 (1 );
}
}
Catch {;}

If (! VisioUtility. HasShapeInWindow (VisWindow ))
{
MessageUtil. ShowWarning ("no device on the drawing, this operation cannot be performed ");
Return;
}
# Endregion

App. UndoEnabled = false;
List <string> list = new List <string> ();
String message = "";
List = powerCutBLL. RunPowerCutAnalyzing (app, shapeSelected, ref message );
App. UndoEnabled = true;

If (message! =
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.