本格的なAPIの開発-SolidWorksソフトウェアパッケージ用のアプリケーション。 ボルトモデル

はじめに



前の資料では、SolidWorks 3Dモデリングシステム用のAPIアプリケーションを開発するための基本原則を概説しました。 この記事では、設計エンジニアの効率を高めるために設計されたアプリケーションである実際のAPIの開発を紹介したいと思います。

設計段階の1つは、製品の3次元モデルの開発です。 複雑なアセンブリは、設計者自身が直接開発した多くの標準化されたファスナーを使用します。

もちろん、代替オプションはSolidWorksの構成を使用することですが、標準化されていないファスナーを使用する必要がある場合、エンジニアは必要なサイズと構成を事前に知りません。 したがって、複雑な部品の開発と組み立てのプロセスは、ファスナーをモデル化する必要があるため、常に中断されます。

この作業の一環として、APIが開発されました。これは、指定された幾何学的パラメーターを持つボルトモデルを自動的に作成するためのアプリケーションです。

目標と目的



この作業の目的は、設計された製品をモデリングする段階で、エンジニア(設計者)の労働効率を高めることです。 目標に従って、次のタスクが特定されました。

•ボルトの標準モデルの開発。

•APIの作成-アプリケーション。

•モデル構築を実装するライブラリの開発。

開発ツール



•SolidWorks;

•C#;

•WPF;

•VSTA(Visual Studio Tools for Applications);

モデル開発



モデリングの結果、次の図に示す3次元モデルが得られました。



インターフェース設計



アプリケーションインターフェイスを開発するためのツールとして、Windows Presentation Foundationテクノロジが選択されました。 インターフェイスのXAMLマークアップがリストに表示されます。

<Window x:Class="APIHabr.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="API-" Height="250" Width="375"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="auto"></RowDefinition> <RowDefinition Height="auto"></RowDefinition> <RowDefinition Height="auto"></RowDefinition> <RowDefinition Height="auto"></RowDefinition> <RowDefinition Height="auto"></RowDefinition> <RowDefinition Height="auto"></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"></ColumnDefinition> <ColumnDefinition Width="auto"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBlock Grid.Row="0" Grid.Column="0" Margin="5,5,5,5" FontSize="16" FontWeight="Bold"> :</TextBlock> <TextBlock Grid.Row="1" Grid.Column="0" Margin="5,5,5,5" FontSize="16"> :</TextBlock> <TextBlock Grid.Row="2" Grid.Column="0" Margin="5,5,5,5" FontSize="16"> :</TextBlock> <TextBlock Grid.Row="3" Grid.Column="0" Margin="5,5,5,5" FontSize="16">  :</TextBlock> <TextBlock Grid.Row="4" Grid.Column="0" Margin="5,5,5,5" FontSize="16">:</TextBlock> <Button Grid.Row="5" Grid.Column="1" Width="170" Height="30" Margin="5,5,5,5" Content="" FontSize="16"></Button> <TextBox Grid.Column="1" Grid.Row="1" Margin="5,5,5,5"></TextBox> <TextBox Grid.Column="1" Grid.Row="2" Margin="5,5,5,5"></TextBox> <TextBox Grid.Column="1" Grid.Row="3" Margin="5,5,5,5"></TextBox> <TextBox Grid.Column="1" Grid.Row="4" Margin="5,5,5,5"></TextBox> </Grid> </Window>
      
      





その結果、次の図に示すように、簡素化されたアプリケーションインターフェイスが開発されました。



ソフトウェア実装



 public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public SldWorks swApp; void Button_Click_1(object sender, RoutedEventArgs e) { ModelDoc2 swDoc = null; PartDoc swPart = null; DrawingDoc swDrawing = null; AssemblyDoc swAssembly = null; bool boolstatus = false; int longstatus = 0; int longwarnings = 0; swDoc = ((ModelDoc2)(swApp.ActiveDoc)); OpenDoc(ref swDoc, ref longstatus, ref longwarnings); swApp.ActivateDoc2("", false, ref longstatus); swDoc = ((ModelDoc2)(swApp.ActiveDoc)); ModelView myModelView = null; boolstatus = GrooveDiameter(swDoc, boolstatus); boolstatus = SetBoltHeadHeight(swDoc, boolstatus); boolstatus = SetDimensionUnderKey(swDoc, boolstatus); boolstatus = SetLength(swDoc, boolstatus); } //   static bool SetLength(ModelDoc2 swDoc, bool boolstatus) { boolstatus = swDoc.Extension.SelectByID2("", "FACE", 0.011912467420266637, 0.01846469011343288, 0.0037872311733622155, false, 0, null, 0); boolstatus = swDoc.Extension.SelectByID2("D1@1@.SLDPRT", "DIMENSION", 0.047351053302585169, 0.019301296053367275, 0.0028786441805853363, true, 0, null, 0); boolstatus = swDoc.EditRebuild3(); swDoc.ClearSelection2(true); return boolstatus; } //     static bool SetDimensionUnderKey(ModelDoc2 swDoc, bool boolstatus) { boolstatus = swDoc.Extension.SelectByID2("", "FACE", -0.00036826155354674484, 0.051999999999850388, -0.0013844273092900039, false, 0, null, 0); boolstatus = swDoc.Extension.SelectByID2("D4@1@.SLDPRT", "DIMENSION", 0.0079871009577274082, 0.035833016414888383, -0.013439947146820423, true, 0, null, 0); boolstatus = swDoc.EditRebuild3(); swDoc.ClearSelection2(true); return boolstatus; } //    static bool SetBoltHeadHeight(ModelDoc2 swDoc, bool boolstatus) { boolstatus = swDoc.Extension.SelectByID2("", "FACE", 0.0025916945023696791, 0.022486595775220126, 0.012228373547031879, false, 0, null, 0); boolstatus = swDoc.Extension.SelectByID2("D2@1@.SLDPRT", "DIMENSION", 0.032400529167230879, 0.043963039647934993, 0, true, 0, null, 0); boolstatus = swDoc.EditRebuild3(); swDoc.ClearSelection2(true); return boolstatus; } //    static bool GrooveDiameter(ModelDoc2 swDoc, bool boolstatus) { boolstatus = swDoc.Extension.SelectByID2("", "FACE", -0.00081167638456329516, 0.026711469979688613, 0.0089633242408808655, false, 0, null, 0); boolstatus = swDoc.Extension.SelectByID2("D3@1@.SLDPRT", "DIMENSION", 0.0056429925389302749, 0.040324953527420437, 0, true, 0, null, 0); boolstatus = swDoc.EditRebuild3(); swDoc.ClearSelection2(true); return boolstatus; } //  void OpenDoc(ref ModelDoc2 swDoc, ref int longstatus, ref int longwarnings) { swDoc = ((ModelDoc2)(swApp.OpenDoc6("D:\\\\Item2\\.SLDPRT", 1, 0, "", ref longstatus, ref longwarnings))); } }
      
      





おわりに



このようなAPIアプリケーションの主な目標は、モデルの作成プロセスを自動化することです。 この作業のフレームワークでは、ファスナー(ボルト)の自動化モデリングのみが考慮されました。 将来的には、次の自動化の問題が考慮されます。

•API-SolidWorksソフトウェアパッケージの典型的な構造のモデルを組み立てるためのアプリケーション。

•API-設計ドキュメントの開発を自動化するためのアプリケーション。

•API-複雑な製品をモデリングするためのアプリケーション。



All Articles