Skip to content

Instantly share code, notes, and snippets.

@zflat
Last active December 17, 2015 22:29
Show Gist options
  • Save zflat/5682361 to your computer and use it in GitHub Desktop.
Save zflat/5682361 to your computer and use it in GitHub Desktop.
array of doubles as OLE set parameters
#include <comdef.h>
// ...
HRESULT hres = CoInitializeEx(0, COINIT_MULTITHREADED);
QAxObject* swApp = new QAxObject("SldWorks.Application");
CoUninitialize();

Batch mode solidworks: http://ossandcad.blogspot.com/2008/04/batch-mode-solidworks.html

Example use case:

http://help.solidworks.com/2011/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IModelDoc2~MaterialPropertyValues.html

MaterialPropertyValues Property (IModelDoc2)
C++/CLI	 
property Object^ MaterialPropertyValues {
   Object^ get();
   void set (Object^ value);
}

Background on setters http://www.codeguru.com/cpp/cpp/cpp_managed/general/article.php/c14815/CCLI-Primer.htm http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1600.html http://www.codeproject.com/Articles/10352/C-CLI-Properties-Syntactic-sugar-for-accessor-meth http://msdn.microsoft.com/en-us/library/vstudio/2f1ec0b1.aspx

Troubleshooting method info: http://compgroups.net/comp.lang.ruby/win32ole-passing-an-array-to-autocad/747477 http://www.ruby-doc.org/stdlib-2.0/libdoc/win32ole/rdoc/WIN32OLE_METHOD.html

Wrapping the object in the correct type: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/win32ole/rdoc/WIN32OLE_VARIANT.html http://www.ruby-doc.org/stdlib-2.0/libdoc/win32ole/rdoc/WIN32OLE/VARIANT.html http://www.pocketsoap.com/4s4c/docs/datatypes.html

Getter works

vals = model.MaterialPropertyValues

Naive setter does not behave as expected

model.MaterialPropertyValues = vals # sets to some erroneous values

See method info

h = model.ole_method_help('MaterialPropertyValues=')
puts h.name
puts " dispid:"
puts "   #{h.dispid}"
puts " args:"
h.params.each do |p|
  puts "   #{p.ole_type} #{p.name}"
end

Use an array of doubles

arr = WIN32OLE_VARIANT.array([vals.count], WIN32OLE::VARIANT::VT_R8)
(0..vals.count-1).to_a.each do |i|
   arr[i] = vals[i]
end
model.MaterialPropertyValues = arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment