def update_marker_coords(self, mkr_name, mkr_pts): ret = 0 start_frame = self.get_start_frame_number() n_total_frames = self.get_total_frame_counts() input_pts_dim = mkr_pts.ndim input_pts_shape = mkr_pts.shape if input_pts_dim != 2 or input_pts_shape[0] != n_total_frames: print("The dimension of the input is not compatible!") return False mkr_idx = self.get_marker_index(mkr_name) if mkr_idx == -1: return False variant = win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R4, np.nan_to_num(mkr_pts[:, 0])) ret = self.itf.SetPointDataEx(mkr_idx, 0, start_frame, variant) variant = win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R4, np.nan_to_num(mkr_pts[:, 1])) ret = self.itf.SetPointDataEx(mkr_idx, 1, start_frame, variant) variant = win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R4, np.nan_to_num(mkr_pts[:, 2])) ret = self.itf.SetPointDataEx(mkr_idx, 2, start_frame, variant) var_const = win32.VARIANT(pythoncom.VT_R4, 1) for idx, val in enumerate(mkr_pts[:, 0]): if val == 1: ret = self.itf.SetPointData(mkr_idx, 0, start_frame + idx, var_const) for idx, val in enumerate(mkr_pts[:, 1]): if val == 1: ret = self.itf.SetPointData(mkr_idx, 1, start_frame + idx, var_const) for idx, val in enumerate(mkr_pts[:, 2]): if val == 1: ret = self.itf.SetPointData(mkr_idx, 2, start_frame + idx, var_const) if ret == 1: return True else: return False
def update_marker_residual(self, mkr_name, mkr_resid): ret = 0 start_frame = self.get_start_frame_number() n_total_frames = self.get_total_frame_counts() input_resid_dim = mkr_resid.ndim input_resid_shape = mkr_resid.shape if input_resid_dim != 1 or input_resid_shape[0] != n_total_frames: print("The dimension of the input is not compatible!") return False mkr_idx = self.get_marker_index(mkr_name) if mkr_idx == -1: return False variant = win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R4, mkr_resid) ret = self.itf.SetPointDataEx(mkr_idx, 3, start_frame, variant) var_const = win32.VARIANT(pythoncom.VT_R4, 1) for idx, val in enumerate(mkr_resid): if val == 1: ret = self.itf.SetPointData(mkr_idx, 3, start_frame + idx, var_const) if ret == 1: return True else: return False
# -*- coding: utf-8 -*- import datetime import numpy as np import pandas as pd import pythoncom import pywintypes from win32com import client A = 0 B = 0 V = client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_VARIANT, 2) class IbaDatFile(object): """ Class representing an Iba .dat file """ def __init__(self, path=None, raw_mode: bool = False, preload: bool = True): """ initialize the dat file object """ self.path = path try: self.reader = client.dynamic.Dispatch("IbaFilesLite.IbaFile") except pywintypes.com_error: raise IOError("Necessary dlls are not installed.")
Spyder Editor This is a temporary script file. """ import win32com.client as client import pythoncom sw = client.Dispatch("SldWorks.Application") cosmos = sw.GetAddInObject("SldWorks.Simulation") cwork = cosmos.CosmosWorks act_doc = cwork.ActiveDoc studymgr = act_doc.StudyManager static = studymgr.GetStudy(0) lrmgr = static.LoadsAndRestraintsManager x = 0 arg1 = client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, 0) #l= lrmgr.GetLoadsAndRestraints(0,arg1) part = sw.ActiveDoc selMgr = part.SelectionManager print(selMgr.GetSelectionPoint2(1, -1)) #swFeat = selMgr.GetSelectedObject6(1,-1) #sketch = swFeat.GetSpecificFeature #points = sketch.GetSketchPoints2 #point = points[0] #print(point.GetCoords) xl = client.Dispatch("Excel.Application") xl.WorkBooks.Add() xl.Visible = 1 sheet = xl.ActiveSheet for i in range(0, lrmgr.Count): p = [500, 1000, 2000, 10000, 30000, 60000, 100000]
def make_point(x, y, z=0.0): # функция нужна только для питона return client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, [x, y, z])
import win32com.client as wclient import pythoncom import os from shutil import copy2 from swconst import SwConstants MODELS_TEMPLATE_FOLDER = os.path.abspath('original_files\\models') PRJ_FOLDER = os.path.abspath('projects') MODELS_FOLDER = '3d_models' DXF_FOLDER = 'dxf' arg1 = wclient.VARIANT(pythoncom.VT_DISPATCH, None) arg2 = wclient.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, -1) copied_files = [] new_model_files = {} def copyfiles(name, src, prjname): copy_to = os.path.join(models_path, f'{"_".join(name.split(".")[:-1])}_{prjname}.{name.split(".")[-1]}') copy2(src, copy_to) copied_files.append(src) print(f'{name} copied') return copy_to while True: prj_name = input("Название проекта: ") if not os.path.exists(os.path.join(PRJ_FOLDER, prj_name)):
def POINT(x, y, z): return win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))
import win32com.client as Client import pythoncom sw = Client.Dispatch("SldWorks.Application") number = input("Number: ") xl = Client.Dispatch('Excel.Application') name = xl.Worksheets(1).Range('A:A').Find(int(number)).Cells(1, 2).Value #name = input("Name: ") path = "E:\Data\\2020 Documents\Subsystems\Chassis\Cartesian\\" + number + "_" + name + ".SLDPRT" part = sw.ActiveDoc arg = Client.VARIANT(pythoncom.VT_I4 | pythoncom.VT_BYREF, 0) if not part.SaveToFile3(path, 2, 2, False, '', arg, arg): print("Failure") else: sw.CloseDoc("") print("Created file " + number + "_" + name + ".SLDPRT")
def vshort(i): return wc.VARIANT(pc.VT_BYREF | pc.VT_I2, i)
def vstrarr(list): return wc.VARIANT(pc.VT_BYREF | pc.VT_ARRAY | pc.VT_BSTR, list)
def vstr(str): return wc.VARIANT(pc.VT_BSTR, str)
def vint(i): return wc.VARIANT(pc.VT_I4, i)
def add_marker(self, mkr_name, mkr_pts): start_frame = self.itf.GetVideoFrame(0) n_total_frames = self.get_total_frame_counts() input_pts_dim = mkr_pts.ndim input_pts_shape = mkr_pts.shape if input_pts_dim != 2 or input_pts_shape[0] != n_total_frames: print("The dimension of the input is not compatible!") return False ret = 0 # Add an parameter to the 'POINT:LABELS' section par_idx_point_labels = self.itf.GetParameterIndex('POINT', 'LABELS') ret = self.itf.AddParameterData(par_idx_point_labels, 1) cnt_point_labels = self.itf.GetParameterLength(par_idx_point_labels) variant = win32.VARIANT(pythoncom.VT_BSTR, np.string_(mkr_name)) ret = self.itf.SetParameterValue(par_idx_point_labels, cnt_point_labels - 1, variant) # Add a null parameter in the 'POINT:DESCRIPTIONS' section par_idx_point_desc = self.itf.GetParameterIndex( 'POINT', 'DESCRIPTIONS') ret = self.itf.AddParameterData(par_idx_point_desc, 1) cnt_point_desc = self.itf.GetParameterLength(par_idx_point_desc) variant = win32.VARIANT(pythoncom.VT_BSTR, np.string_(mkr_name)) ret = self.itf.SetParameterValue(par_idx_point_desc, cnt_point_desc - 1, variant) # Add a marker new_mkr_idx = self.itf.AddMarker() cnt_mkrs = self.itf.GetNumber3DPoints() arr_zeros = np.zeros((n_total_frames, ), dtype=np.float32) arr_masks = np.array(["0000000"] * n_total_frames, dtype=np.string_) variant = win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R4, np.nan_to_num(mkr_pts[:, 0])) ret = self.itf.SetPointDataEx(cnt_mkrs - 1, 0, start_frame, variant) variant = win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R4, np.nan_to_num(mkr_pts[:, 1])) ret = self.itf.SetPointDataEx(cnt_mkrs - 1, 1, start_frame, variant) variant = win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R4, np.nan_to_num(mkr_pts[:, 2])) ret = self.itf.SetPointDataEx(cnt_mkrs - 1, 2, start_frame, variant) variant = win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R4, arr_zeros) ret = self.itf.SetPointDataEx(cnt_mkrs - 1, 3, start_frame, variant) variant = win32.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_BSTR, arr_masks) ret = self.itf.SetPointDataEx(cnt_mkrs - 1, 4, start_frame, variant) for idx, val in enumerate(mkr_pts[:, 0]): if val == 1: variant = win32.VARIANT(pythoncom.VT_R4, val) ret = self.itf.SetPointData(cnt_mkrs - 1, 0, start_frame + idx, variant) for idx, val in enumerate(mkr_pts[:, 1]): if val == 1: variant = win32.VARIANT(pythoncom.VT_R4, val) ret = self.itf.SetPointData(cnt_mkrs - 1, 1, start_frame + idx, variant) for idx, val in enumerate(mkr_pts[:, 2]): if val == 1: variant = win32.VARIANT(pythoncom.VT_R4, val) ret = self.itf.SetPointData(cnt_mkrs - 1, 2, start_frame + idx, variant) # Increase the value 'POINT:USED' by the 1 par_idx_point_used = self.itf.GetParameterIndex('POINT', 'USED') cnt_point_used = self.itf.GetParameterValue(par_idx_point_used, 0) par_idx_point_labels = self.itf.GetParameterIndex('POINT', 'LABELS') cnt_point_labels = self.itf.GetParameterLength(par_idx_point_labels) if cnt_point_used != cnt_point_labels: ret = self.itf.SetParameterValue(par_idx_point_used, 0, cnt_point_labels) if ret == 1: return True else: return False