def add_component(self, i_reference_product: Product) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445)) | o Func AddComponent(Product iReferenceProduct) As Product | | Creates a component and adds it to the Products collection. A component is | a Product object created from another Product object used as | reference. | | Parameters: | | iReferenceProduct | The product used as reference | | Example: | | The following example creates the SpareWheel component | from | the reference product FrontRightWheel and adds the | component | to the ToolKits collection. | | | Dim SpareWheel As Product | Set SpareWheel = ToolKits.AddComponent(FrontRightWheel) :param Product i_reference_product: :return: Product :rtype: Product """ return Product( self.products.AddComponent(i_reference_product.com_object))
def set_all_children(self, product=None, level=0): """Loops through the product and determine if item is part or product. If product was found, the function is executed again. Args: product (com_object): Contains the part or product class. level (int): Provides information about the level of the respective part or product in the structure tree. """ if not product: product = self.active_file self.add_children(level, product, "CATPart") if product.is_catpart( ) else self.add_children(level, product, "CATProduct") level += 1 for i in range(product.count_children()): self.count_item += 1 item = product.get_child(i) if item.is_catpart(): sub_item = Part(item.product) self.add_children(level, sub_item, "CATPart") elif item.is_catproduct(): sub_item = Product(item.product) self.add_children(level, sub_item, "CATProduct") self.set_all_children(sub_item, level) self.set_parts() self.set_products()
def first_product(self) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-07-06 14:02:20.222384) | o Property FirstProduct() As Product (Read Only) | | Returns the product belonging to the first group that realizes the minimum | distance. | | Example: | | This example retrieves the first product involved in the | NewDistance Distance. | | | Dim AProduct As Product | Set AProduct = NewDistance.FirstProduct :return: Product :rtype: Product """ return Product(self.distance.FirstProduct)
def product(self) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445) | o Property Product() As Product (Read Only) | | Returns the root product. | | Example: | | This example retrieves the root product of the | MyProductDoc | ProductDocument in RootProduct. | | | Dim RootProduct As Product | Set RootProduct = MyProductDoc.Product :return: Product :rtype: Product """ return Product(self.product_document.Product)
def item_invert(self, i_index: cat_variant) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-07-06 14:02:20.222384)) | o Func ItemInvert(CATVariant iIndex) As Product | | Returns a terminal node product which cannot be extracted from the group | using its index. | | Parameters: | | iIndex | The index of the product in the group. The index of the first | product is 1, and the index of the last product is CountExtract. | | | Returns: | The retrieved product | Example: | | This example retrieves in ThisProduct the ninth product which | cannot be extracted from | the NewGroup group. | | | Dim ThisProduct As Group | Set ThisProduct = NewGroup.ItemInvert(9) :param cat_variant i_index: :return: Product :rtype: Product """ return Product(self.group.ItemInvert(i_index))
def second_product(self) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-07-06 14:02:20.222384) | o Property SecondProduct() As Product (Read Only) | | Returns the product belonging to the second group that realizes the minimum | distance. | | Example: | | This example retrieves the coordinates in the NewDistance | Distance. | | | Dim AProduct As Product | Set AProduct = NewDistance.SecondProduct :return: Product :rtype: Product """ return Product(self.distance.SecondProduct)
def add_new_product(self, i_part_number: str) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445)) | o Func AddNewProduct(CATBSTR iPartNumber) As Product | | Creates a Product reference object. This creates a Product reference object | and the associated component by specifying its type and adds it to the Products | collection. | | Parameters: | | iPartNumber | The part number of the product to be created and added to the to | the collection | | Example: | | The following example creates the Engine product | and adds the created component to the PowerTrains | collection. | | | Dim Engine As Product | Set Engine = PowerTrains.AddNewProduct(V6Engine) :param str i_part_number: :return: Product :rtype: Product """ return Product(self.products.AddNewProduct(i_part_number))
def test_move(): with CATIADocHandler(cat_product) as caa: product = caa.document.product() product.apply_work_mode(cat_work_mode_type.index("DESIGN_MODE")) transformation = (1.000, 0, 0, 0, 0.707, 0.707, 0, -0.707, 0.707, 10.000, 20.000, 30.000) Product.activate_terminal_node(product.get_products()) # move the first child in parent. product = product.get_products()[0] product.move.apply(transformation) assert ((520.8333333333333, 0.0, 0.0, 0.0, 677.0833333333264, -156.24999999999818, 0.0, -156.24999999999818, 677.0833333333264) == product.analyze.get_inertia())
def item(self, i_index: cat_variant) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445)) | o Func Item(CATVariant iIndex) As Product | | Returns a product from its index in the Products | collection. | | Parameters: | | iIndex | The index of the product to retrieve in the collection of products. | This index can either be the rank of the product in the collection or the name | you assign to the product. As a numerics, this index is the rank of the product | in the collection. The index of the first product in the collection is 1, and | the index of the last product is Count. As a string, it is the name you | assigned to the product using the | | AnyObject.Name property | Returns: | The retrieved product | Example: | | The following example returns in ThisProduct the third | product, | and in ThatProduct the product named | Wheel in the CarParts product collection. | | | Dim ThisProduct As Product | Set ThisProduct = CarParts.Item(3) | Dim ThatProduct As Product | Set ThatProduct = CarParts.Item("Wheel") :param cat_variant i_index: :return: Product :rtype: Product """ return Product(self.products.Item(i_index))
def product(self) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-07-06 14:02:20.222384) | o Property Product() As Product (Read Only) | | Returns the root Product object from the current part | document. | | Example: | The following example retrieves in RootProd the root Product object of | the active document, assumed to be a part document: | | Set RootProd = CATIA.ActiveDocument.Part :return: Product :rtype: Product """ return Product(self.part_document.Product)
def replace_component(self, i_old_component: Product, i_file_path: str, i_multi_instances: bool) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445)) | o Func ReplaceComponent(Product iOldComponent, | CATBSTR iFilePath, | boolean iMultiInstances) As Product | | Creates a component which replace the given one. | | Parameters: | | iOldComponent | The component which will be replaced | iFilePath | the document to replace with | iMultiInstances | Parameter to set to True if all instances are to be replaced, or to | False otherwise. Returns the component replacing | iOldComponent | | | Note: | Part Number conflict will be resolved | automatically. :param Product i_old_component: :param str i_file_path: :param bool i_multi_instances: :return: Product :rtype: Product """ return Product( self.products.ReplaceComponent(i_old_component.com_object, i_file_path, i_multi_instances))
def get_product(self, i_index: cat_variant) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-07-06 14:02:20.222384)) | o Func GetProduct(CATVariant iIndex) As Product | | Returns a Product using its index or its name in the | FixTogether. | | Parameters: | | iIndex | The index or the name of the Product to retrieve. As a numerics, | this index is the rank of the Product in the products of the FixTogether. The | index of the first Product is 1, and the index of the last Product is | ProductsCount. As a string, it is the name you assigned to the Product using | the | | AnyObject.Name property. | Returns: | The retrieved Product | Example: | This example retrieves in thisProduct the fifth Product and in | thatProduct the Product named myProduct in the products of the | FixTogether. | | Dim thisProduct As Product | Set thisProduct = myFixTogether.GetProduct(5) | Dim thatProduct As Product | Set thatProduct = myFixTogether.GetProduct("myProduct") :param cat_variant i_index: :return: Product :rtype: Product """ return Product(self.fix_together.GetProduct(i_index))
def add_external_component(self, i_product_document: 'Document') -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445)) | o Func AddExternalComponent(Document iProductDocument) As | Product | | Creates a component from the root product of another ProductDocument | object. This root product is used as a reference to create the component. The | component is added to the Products collection. | | Parameters: | | iProductDocument | The product document whose root object is to be used as reference | to create the component | | Example: | | The following example creates the GearBox component | by | referencing the GearBoxDocument and adds it | to the PowerTrains collection. | | | Dim GearBox As Product | Set GearBox = PowerTrains.AddExternalComponent(GearBoxDocument) :param Document i_product_document: :return: Product :rtype: Product """ return Product( self.products.AddExternalComponent(i_product_document.com_object))
def add_new_component(self, i_documen_type: str, i_part_number: str) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445)) | o Func AddNewComponent(CATBSTR iDocumenType, | CATBSTR iPartNumber) As Product | | Creates a component from the root product of a new ProductDocument object. | This root product is used as a reference to create the component. The component | is added to the Products collection. | | Parameters: | | iProductDocument | The product document whose root object is to be used as reference | to create the component | | Example: | | The following example creates the GearBox component | by | referencing the GearBoxDocument and adds it | to the PowerTrains collection. | | | Dim GearBox As Product | Set GearBox = PowerTrains.AddNewComponent(GearBoxDocument, "A120-253X-7") :param str i_documen_type: :param str i_part_number: :return: Product """ return Product( self.products.AddNewComponent(i_documen_type, i_part_number))
def second_product(self) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-07-06 14:02:20.222384) | o Property SecondProduct() As Product (Read Only) | | Returns the second product involved in the conflict. | | Example: | | This example retrieves the second product involved in the | NewConflict Conflict. | | | Dim aProduct As Product | Set aProduct = NewConflict.SecondProduct :return: Product :rtype: Product """ return Product(self.conflict.SecondProduct)
def replace_product(self, i_old_component: Product, i_new_reference: Product, i_multi_instances: bool) -> Product: """ .. note:: :class: toggle CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445)) | o Func ReplaceProduct(Product iOldComponent, | Product iNewReference, | boolean iMultiInstances) As Product | | Creates a component which replace the given one. | | Parameters: | | iOldComponent | The component which will be replaced | iNewReference | the reference whom the old copmponent will be reconnected | | iMultiInstances | Parameter to set to True if all instances are to be replaced, or to | False otherwise. Returns the component replacing | iOldComponent :param Product i_old_component: :param Product i_new_reference: :param bool i_multi_instances: :return: Product :rtype: Product """ return Product( self.products.ReplaceProduct(i_old_component.com_object, i_new_reference.com_object, i_multi_instances))
sys.path.insert(0, os.path.abspath('..\\pycatia')) ########################################################## from pycatia import catia from pycatia.enumeration.enumeration_types import cat_work_mode_type from pycatia.product_structure_interfaces.product import Product caa = catia() documents = caa.documents documents.open(r'tests\cat_files\product_top.CATProduct') document = caa.active_document product = document.product() # Change the work mode to Design Mode. # This is useful for CATIA configurations that work with a cache otherwise methods on children may fail # due to the document not being loaded. product.apply_work_mode(cat_work_mode_type.index("DESIGN_MODE")) # Transformation matrix (45 degrees-rotation around the x axis and a translation). transformation = (1.000, 0, 0, 0, 0.707, 0.707, 0, -0.707, 0.707, 10.000, 20.000, 30.000) # activates default shape on all children. Product.activate_terminal_node(product.products) # move the first child in parent. product = product.products[0] move = product.move.apply(transformation)
Move the first child in product. """ from pycatia import catia from pycatia.enumeration.enumeration_types import cat_work_mode_type from pycatia.product_structure_interfaces.product import Product caa = catia() documents = caa.documents documents.open(r'tests\cat_files\product_top.CATProduct') document = caa.active_document product = document.product() # Change the work mode to Design Mode. # This is useful for CATIA configurations that work with a cache otherwise methods on children may fail # due to the document not being loaded. product.apply_work_mode(cat_work_mode_type.index("DESIGN_MODE")) # Transformation matrix (45 degrees-rotation around the x axis and a translation). transformation = (1.000, 0, 0, 0, 0.707, 0.707, 0, -0.707, 0.707, 10.000, 20.000, 30.000) # activates default shape on all children. Product.activate_terminal_node(product.get_products()) # move the first child in parent. product = product.get_products()[0] move = product.move.apply(transformation)
def product(self): """ :return: :class:`Product()` """ return Product(self.document.Product)
def __getitem__(self, n: int) -> Product: if (n + 1) > self.count: raise StopIteration return Product(self.products.item(n + 1))