Skip to content

Commit b7191e3

Browse files
committed
Implemented #32 - Add support for dimension change notification enhancement
Updated SwEx.Common to 0.9.9 Added the backward compatibility for SW 2012 onwards
1 parent de7e78c commit b7191e3

23 files changed

+252
-40
lines changed

AddInExample/AddInExample.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@
3131
<WarningLevel>4</WarningLevel>
3232
</PropertyGroup>
3333
<ItemGroup>
34-
<Reference Include="CodeStack.SwEx.Common, Version=0.9.8.0, Culture=neutral, PublicKeyToken=a46023996d4724e7, processorArchitecture=MSIL">
35-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\CodeStack.SwEx.Common.dll</HintPath>
34+
<Reference Include="CodeStack.SwEx.Common, Version=0.9.9.0, Culture=neutral, PublicKeyToken=a46023996d4724e7, processorArchitecture=MSIL">
35+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\CodeStack.SwEx.Common.dll</HintPath>
3636
</Reference>
3737
<Reference Include="SolidWorks.Interop.sldworks, Version=27.1.0.72, Culture=neutral, PublicKeyToken=7c4797c3e4eeac03, processorArchitecture=MSIL">
38-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorks.Interop.sldworks.dll</HintPath>
38+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorks.Interop.sldworks.dll</HintPath>
3939
<EmbedInteropTypes>False</EmbedInteropTypes>
4040
</Reference>
4141
<Reference Include="SolidWorks.Interop.swconst, Version=27.1.0.72, Culture=neutral, PublicKeyToken=19f43e188e4269d8, processorArchitecture=MSIL">
42-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorks.Interop.swconst.dll</HintPath>
42+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorks.Interop.swconst.dll</HintPath>
4343
<EmbedInteropTypes>False</EmbedInteropTypes>
4444
</Reference>
4545
<Reference Include="SolidWorks.Interop.swpublished, Version=27.1.0.72, Culture=neutral, PublicKeyToken=89a97bdc5284e6d8, processorArchitecture=MSIL">
46-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorks.Interop.swpublished.dll</HintPath>
46+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorks.Interop.swpublished.dll</HintPath>
4747
<EmbedInteropTypes>False</EmbedInteropTypes>
4848
</Reference>
4949
<Reference Include="SolidWorksTools, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bd18593873b4686d, processorArchitecture=MSIL">
50-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorksTools.dll</HintPath>
50+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorksTools.dll</HintPath>
5151
</Reference>
5252
<Reference Include="System" />
5353
<Reference Include="System.Core" />

AddInExample/SwSampleAddIn.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,16 @@ private void OnHandlerCreated(DocumentHandler handler)
258258
handler.Save += OnSave;
259259
handler.Selection += OnSelection;
260260
handler.Rebuild += OnRebuild;
261+
handler.DimensionChange += OnDimensionChange;
261262
handler.Destroyed += OnDestroyed;
262263
}
263264

265+
private void OnDimensionChange(DocumentHandler docHandler, IDisplayDimension dispDim)
266+
{
267+
App.SendMsgToUser2($"'{docHandler.Model.GetTitle()}' dimension change: {dispDim.IGetDimension().FullName} = {dispDim.IGetDimension().Value}",
268+
(int)swMessageBoxIcon_e.swMbInformation, (int)swMessageBoxBtn_e.swMbOk);
269+
}
270+
264271
private bool OnRebuild(DocumentHandler docHandler, RebuildState_e type)
265272
{
266273
return App.SendMsgToUser2($"'{docHandler.Model.GetTitle()}' rebuilt ({type}). Cancel?",
@@ -283,6 +290,7 @@ private void OnDestroyed(DocumentHandler handler)
283290
handler.Save -= OnSave;
284291
handler.Selection -= OnSelection;
285292
handler.Rebuild -= OnRebuild;
293+
handler.DimensionChange -= OnDimensionChange;
286294
handler.Destroyed -= OnDestroyed;
287295

288296
App.SendMsgToUser2($"'{handler.Model.GetTitle()}' destroyed",

AddInExample/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="CodeStack.SwEx.Common" version="0.9.8" targetFramework="net40" />
3+
<package id="CodeStack.SwEx.Common" version="0.9.9" targetFramework="net40" />
44
</packages>

Framework.Tests/Framework.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,27 @@
4949
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
5050
<Private>True</Private>
5151
</Reference>
52-
<Reference Include="CodeStack.SwEx.Common, Version=0.9.8.0, Culture=neutral, PublicKeyToken=a46023996d4724e7, processorArchitecture=MSIL">
53-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\CodeStack.SwEx.Common.dll</HintPath>
52+
<Reference Include="CodeStack.SwEx.Common, Version=0.9.9.0, Culture=neutral, PublicKeyToken=a46023996d4724e7, processorArchitecture=MSIL">
53+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\CodeStack.SwEx.Common.dll</HintPath>
5454
</Reference>
5555
<Reference Include="Moq, Version=4.9.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
5656
<HintPath>..\packages\Moq.4.9.0\lib\net45\Moq.dll</HintPath>
5757
<Private>True</Private>
5858
</Reference>
5959
<Reference Include="SolidWorks.Interop.sldworks, Version=27.1.0.72, Culture=neutral, PublicKeyToken=7c4797c3e4eeac03, processorArchitecture=MSIL">
60-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorks.Interop.sldworks.dll</HintPath>
60+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorks.Interop.sldworks.dll</HintPath>
6161
<EmbedInteropTypes>False</EmbedInteropTypes>
6262
</Reference>
6363
<Reference Include="SolidWorks.Interop.swconst, Version=27.1.0.72, Culture=neutral, PublicKeyToken=19f43e188e4269d8, processorArchitecture=MSIL">
64-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorks.Interop.swconst.dll</HintPath>
64+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorks.Interop.swconst.dll</HintPath>
6565
<EmbedInteropTypes>False</EmbedInteropTypes>
6666
</Reference>
6767
<Reference Include="SolidWorks.Interop.swpublished, Version=27.1.0.72, Culture=neutral, PublicKeyToken=89a97bdc5284e6d8, processorArchitecture=MSIL">
68-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorks.Interop.swpublished.dll</HintPath>
68+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorks.Interop.swpublished.dll</HintPath>
6969
<EmbedInteropTypes>False</EmbedInteropTypes>
7070
</Reference>
7171
<Reference Include="SolidWorksTools, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bd18593873b4686d, processorArchitecture=MSIL">
72-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorksTools.dll</HintPath>
72+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorksTools.dll</HintPath>
7373
</Reference>
7474
<Reference Include="System" />
7575
<Reference Include="System.Configuration" />

Framework.Tests/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Castle.Core" version="4.3.1" targetFramework="net461" />
4-
<package id="CodeStack.SwEx.Common" version="0.9.8" targetFramework="net461" />
4+
<package id="CodeStack.SwEx.Common" version="0.9.9" targetFramework="net461" />
55
<package id="Moq" version="4.9.0" targetFramework="net461" />
66
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net461" />
77
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />

Framework/Core/DocumentHandler.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class DocumentHandler : IDocumentHandler
3030
private readonly CustomPropertyModifyEventHandler m_CustomPropertyModifyEventHandler;
3131
private readonly ConfigurationChangeEventsHandler m_ConfigurationChangeEventsHandler;
3232
private readonly Access3rdPartyDataEventsHandler m_Access3rdPartyDataEventsHandler;
33+
private readonly DimensionChangeEventsHandler m_DimensionChangeEventsHandler;
3334

3435
/// <summary>
3536
/// Raised when document is initialized
@@ -153,6 +154,21 @@ public event RebuildDelegate Rebuild
153154
}
154155
}
155156

157+
/// <summary>
158+
/// Raised when dimension value is changed in the model
159+
/// </summary>
160+
public event DimensionChangeDelegate DimensionChange
161+
{
162+
add
163+
{
164+
m_DimensionChangeEventsHandler.Attach(value);
165+
}
166+
remove
167+
{
168+
m_DimensionChangeEventsHandler.Detach(value);
169+
}
170+
}
171+
156172
/// <summary>
157173
/// Pointer to the SOLIDWORKS application
158174
/// </summary>
@@ -174,6 +190,7 @@ public DocumentHandler()
174190
m_CustomPropertyModifyEventHandler = new CustomPropertyModifyEventHandler(this);
175191
m_ConfigurationChangeEventsHandler = new ConfigurationChangeEventsHandler(this);
176192
m_Access3rdPartyDataEventsHandler = new Access3rdPartyDataEventsHandler(this);
193+
m_DimensionChangeEventsHandler = new DimensionChangeEventsHandler(this);
177194
}
178195

179196
[Browsable(false)]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//**********************
2+
//SwEx.AddIn - development tools for SOLIDWORKS add-ins
3+
//Copyright(C) 2019 www.codestack.net
4+
//License: https://github.com/codestackdev/swex-addin/blob/master/LICENSE
5+
//Product URL: https://www.codestack.net/labs/solidworks/swex/add-in/
6+
//**********************
7+
8+
using CodeStack.SwEx.AddIn.Core;
9+
using CodeStack.SwEx.AddIn.Enums;
10+
using SolidWorks.Interop.sldworks;
11+
12+
namespace CodeStack.SwEx.AddIn.Delegates
13+
{
14+
/// <summary>
15+
/// Delegate of <see cref="DocumentHandler.DimensionChange"/> event
16+
/// </summary>
17+
/// <param name="docHandler">Document Handler which sends this notification</param>
18+
/// <param name="dispDim">Pointer to the changed <see href="http://help.solidworks.com/2012/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.idisplaydimension_properties.html">display dimension</see></param>
19+
public delegate void DimensionChangeDelegate(DocumentHandler docHandler, IDisplayDimension dispDim);
20+
}

Framework/Enums/ConfigurationChangeState_e.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public enum ConfigurationChangeState_e
1515
/// <summary>
1616
/// Configuration is about to be activated
1717
/// </summary>
18+
/// <remarks>Pre activate for drawing sheets supported from SOLIDWORKS 2013 (revision 21.0)</remarks>
1819
PreActivate,
1920

2021
/// <summary>

Framework/Enums/ItemModificationAction_e.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public enum ItemModificationAction_e
3535
/// <summary>
3636
/// Item is about to be renamed
3737
/// </summary>
38+
/// <remarks>This option is supported from SOLIDWORKS 2016 (revision 24.0)</remarks>
3839
PreRename
3940
}
4041
}

Framework/Framework.csproj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@
4040
<NoWarn>CS1573,CS1591</NoWarn>
4141
</PropertyGroup>
4242
<ItemGroup>
43-
<Reference Include="CodeStack.SwEx.Common, Version=0.9.8.0, Culture=neutral, PublicKeyToken=a46023996d4724e7, processorArchitecture=MSIL">
44-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\CodeStack.SwEx.Common.dll</HintPath>
43+
<Reference Include="CodeStack.SwEx.Common, Version=0.9.9.0, Culture=neutral, PublicKeyToken=a46023996d4724e7, processorArchitecture=MSIL">
44+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\CodeStack.SwEx.Common.dll</HintPath>
4545
</Reference>
4646
<Reference Include="SolidWorks.Interop.sldworks, Version=27.1.0.72, Culture=neutral, PublicKeyToken=7c4797c3e4eeac03, processorArchitecture=MSIL">
47-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorks.Interop.sldworks.dll</HintPath>
47+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorks.Interop.sldworks.dll</HintPath>
4848
<EmbedInteropTypes>False</EmbedInteropTypes>
4949
</Reference>
5050
<Reference Include="SolidWorks.Interop.swconst, Version=27.1.0.72, Culture=neutral, PublicKeyToken=19f43e188e4269d8, processorArchitecture=MSIL">
51-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorks.Interop.swconst.dll</HintPath>
51+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorks.Interop.swconst.dll</HintPath>
5252
<EmbedInteropTypes>False</EmbedInteropTypes>
5353
</Reference>
5454
<Reference Include="SolidWorks.Interop.swpublished, Version=27.1.0.72, Culture=neutral, PublicKeyToken=89a97bdc5284e6d8, processorArchitecture=MSIL">
55-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorks.Interop.swpublished.dll</HintPath>
55+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorks.Interop.swpublished.dll</HintPath>
5656
<EmbedInteropTypes>False</EmbedInteropTypes>
5757
</Reference>
5858
<Reference Include="SolidWorksTools, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bd18593873b4686d, processorArchitecture=MSIL">
59-
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.8\lib\net40\SolidWorksTools.dll</HintPath>
59+
<HintPath>..\packages\CodeStack.SwEx.Common.0.9.9\lib\net40\SolidWorksTools.dll</HintPath>
6060
</Reference>
6161
<Reference Include="System" />
6262
<Reference Include="System.Core" />
@@ -88,6 +88,7 @@
8888
<Compile Include="Delegates\Access3rdPartyDataDelegate.cs" />
8989
<Compile Include="Delegates\ConfigurationChangeDelegate.cs" />
9090
<Compile Include="Delegates\CustomPropertyModifyDelegate.cs" />
91+
<Compile Include="Delegates\DimensionChangeDelegate.cs" />
9192
<Compile Include="Delegates\RebuildDelegate.cs" />
9293
<Compile Include="Delegates\ItemModifyDelegate.cs" />
9394
<Compile Include="Delegates\DocumentSaveDelegate.cs" />
@@ -126,6 +127,7 @@
126127
<Compile Include="Helpers\EventHandlers\DocumentSaveEventsHandler.cs" />
127128
<Compile Include="Helpers\EventHandlers\ItemModifyEventsHandler.cs" />
128129
<Compile Include="Helpers\EventHandlers\ObjectSelectionEventsHandler.cs" />
130+
<Compile Include="Helpers\EventHandlers\DimensionChangeEventsHandler.cs" />
129131
<Compile Include="Helpers\EventHandlers\RebuildEventsHandler.cs" />
130132
<Compile Include="Helpers\EventsHandler.cs" />
131133
<Compile Include="Helpers\RegistrationHelper.cs" />

Framework/Framework.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>CodeStack.SwEx.AddIn</id>
5-
<version>0.8.0</version>
5+
<version>0.8.1</version>
66
<title>Development tools for SOLIDWORKS add-ins</title>
77
<authors>CodeStack</authors>
88
<owners>CodeStack</owners>

Framework/Helpers/CustomPropertiesEventsHandler.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using CodeStack.SwEx.AddIn.Core;
99
using CodeStack.SwEx.AddIn.Delegates;
1010
using CodeStack.SwEx.AddIn.Enums;
11+
using CodeStack.SwEx.Common.Enums;
1112
using SolidWorks.Interop.sldworks;
1213
using System;
1314
using System.Collections.Generic;
@@ -22,7 +23,7 @@ internal class CustomPropertiesEventsHandler : IDisposable
2223
{
2324
private class PropertiesList : Dictionary<string, string>
2425
{
25-
internal PropertiesList(ICustomPropertyManager prpsMgr) : base(StringComparer.CurrentCultureIgnoreCase)
26+
internal PropertiesList(ICustomPropertyManager prpsMgr, ISldWorks app) : base(StringComparer.CurrentCultureIgnoreCase)
2627
{
2728
var prpNames = prpsMgr.GetNames() as string[];
2829

@@ -32,8 +33,15 @@ internal PropertiesList(ICustomPropertyManager prpsMgr) : base(StringComparer.Cu
3233
{
3334
string val;
3435
string resVal;
35-
bool wasRes;
36-
prpsMgr.Get5(prpName, true, out val, out resVal, out wasRes);
36+
if (app.GetVersion() >= SwVersion_e.Sw2014)
37+
{
38+
bool wasRes;
39+
prpsMgr.Get5(prpName, true, out val, out resVal, out wasRes);
40+
}
41+
else
42+
{
43+
prpsMgr.Get4(prpName, true, out val, out resVal);
44+
}
3745
Add(prpName, val);
3846
}
3947
}
@@ -42,17 +50,17 @@ internal PropertiesList(ICustomPropertyManager prpsMgr) : base(StringComparer.Cu
4250

4351
private class PropertiesSet : Dictionary<string, PropertiesList>
4452
{
45-
internal PropertiesSet(IModelDoc2 model) : base(StringComparer.CurrentCultureIgnoreCase)
53+
internal PropertiesSet(ISldWorks app, IModelDoc2 model) : base(StringComparer.CurrentCultureIgnoreCase)
4654
{
47-
Add("", new PropertiesList(model.Extension.CustomPropertyManager[""]));
55+
Add("", new PropertiesList(model.Extension.CustomPropertyManager[""], app));
4856

4957
var confNames = model.GetConfigurationNames() as string[];
5058

5159
if (confNames != null)
5260
{
5361
foreach (var confName in confNames)
5462
{
55-
Add(confName, new PropertiesList(model.Extension.CustomPropertyManager[confName]));
63+
Add(confName, new PropertiesList(model.Extension.CustomPropertyManager[confName], app));
5664
}
5765
}
5866
}
@@ -131,7 +139,7 @@ private int OnIdleNotify()
131139
{
132140
if (!IsWindow(m_CurrentSummaryHandle))
133141
{
134-
FindDifferences(m_CurPrpsSet, new PropertiesSet(m_Model));
142+
FindDifferences(m_CurPrpsSet, new PropertiesSet(m_App, m_Model));
135143
m_CurrentSummaryHandle = IntPtr.Zero;
136144
m_CurPrpsSet = null;
137145
}
@@ -226,7 +234,7 @@ private bool CaptureCurrentProperties()
226234

227235
if (handle != IntPtr.Zero)
228236
{
229-
m_CurPrpsSet = new PropertiesSet(m_Model);
237+
m_CurPrpsSet = new PropertiesSet(m_App, m_Model);
230238
return true;
231239
}
232240
else

Framework/Helpers/EventHandlers/ConfigurationChangeEventsHandler.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using SolidWorks.Interop.sldworks;
1010
using CodeStack.SwEx.AddIn.Core;
1111
using CodeStack.SwEx.AddIn.Enums;
12+
using CodeStack.SwEx.Common.Enums;
1213

1314
namespace CodeStack.SwEx.AddIn.Helpers.EventHandlers
1415
{
@@ -35,7 +36,11 @@ protected override void SubscribeAssemblyEvents(AssemblyDoc assm)
3536

3637
protected override void SubscribeDrawingEvents(DrawingDoc draw)
3738
{
38-
draw.ActivateSheetPreNotify += OnActivateSheetPreNotify;
39+
if (m_DocHandler.App.GetVersion() >= SwVersion_e.Sw2013)
40+
{
41+
draw.ActivateSheetPreNotify += OnActivateSheetPreNotify;
42+
}
43+
3944
draw.ActivateSheetPostNotify += OnActivateSheetPostNotify;
4045
}
4146

@@ -51,7 +56,11 @@ protected override void UnsubscribeAssemblyEvents(AssemblyDoc assm)
5156

5257
protected override void UnsubscribeDrawingEvents(DrawingDoc draw)
5358
{
54-
draw.ActivateSheetPreNotify -= OnActivateSheetPreNotify;
59+
if (m_DocHandler.App.GetVersion() >= SwVersion_e.Sw2013)
60+
{
61+
draw.ActivateSheetPreNotify -= OnActivateSheetPreNotify;
62+
}
63+
5564
draw.ActivateSheetPostNotify -= OnActivateSheetPostNotify;
5665
}
5766

0 commit comments

Comments
 (0)