zoukankan      html  css  js  c++  java
  • NX二次开发-克隆操作

    模板文件:

    克隆替换字符串:

     1 #include "Text.h"
     2 extern DllExport void ufsta(char *param, int *returnCode, int rlen)
     3 {
     4     //克隆的7个步骤 我是“王牌飞行员-里海”欢迎关注我的博客https://www.cnblogs.com/KMould/
     5     //    1. UF_CLONE_initialise
     6     //    2. UF_CLONE_add_assembly UF_CLONE_add_part
     7     //    3. UF_CLONE_set_def_action //指定默认的克隆方式                 
     8     //    4. UF_CLONE_set_name_rule
     9     //    5. UF_CLONE_set_def_directory
    10     //    6. UF_CLONE_perform_clone
    11     //    7. UF_CLONE_terminate
    12     
    13     UF_initialize();
    14     
    15     //初始化一个克隆操作。如果克隆操作已经启动,这个例程将返回UF_CLONE_err_active
    16     UF_CLONE_operation_class_t operation_class = UF_CLONE_clone_operation;
    17     UF_CLONE_initialise(operation_class);
    18     
    19     //UF_CLONE_add_assembly 
    20     //此例程将装配添加到当前克隆操作。
    21     //任何加载错误都将放在load_status输出参数中。
    22 
    23     //UF_CLONE_add_part     添加部件到克隆装配中
    24     //此例程将部件添加到当前克隆操作。如果有子部件,则仅引用不克隆子部件
    25     
    26     //     template01.prt
    27     //       |--template01-1.prt
    28     //       |__template01-2.prt
    29 
    30     UF_PART_load_status_t error_status;
    31     string PartPath = "H:\clone\template\template01.prt";
    32     UF_CLONE_add_assembly(PartPath.c_str(), &error_status);
    33     UF_free_string_array(error_status.n_parts, error_status.file_names);
    34     UF_free(error_status.statuses);
    35 
    36     //指定默认的克隆方式 
    37     //UF_CLONE_clone    克隆
    38     //UF_CLONE_retain   保持
    39     //UF_CLONE_replace  替换
    40     UF_CLONE_action_t action = UF_CLONE_clone;
    41     UF_CLONE_set_def_action(action);
    42 
    43     //指定默认文件名的方法
    44     UF_CLONE_naming_technique_t naming_technique = UF_CLONE_naming_rule;
    45     UF_CLONE_set_def_naming(naming_technique);
    46 
    47     //初始化命名失败结构,需要在执行前调用 
    48     UF_CLONE_naming_failures_t naming_failures;
    49     UF_CLONE_init_naming_failures(&naming_failures);
    50     //定义新装配的克隆命名规则 
    51     UF_CLONE_name_rule_def_t name_rule;
    52     //UF_CLONE_prepend_string  //加前缀
    53     //UF_CLONE_append_string   //加后缀
    54     //UF_CLONE_replace_string  //替换
    55     //UF_CLONE_rename          //重命名
    56     name_rule.type = UF_CLONE_replace_string;
    57     name_rule.base_string = "emp";      //如果替换则输入被替换的字符  //如果是加前缀 加后缀则为"" 
    58     name_rule.new_string = "pme";
    59     UF_CLONE_set_name_rule(&name_rule, &naming_failures);
    60 
    61     //创建或定义克隆部件的存储目录 
    62     UF_CLONE_set_def_directory("H:\clone\Part");
    63     
    64     //执行克隆操作 
    65     UF_CLONE_perform_clone(&naming_failures);
    66 
    67     if (naming_failures.n_failures > 0)
    68     {
    69         UF_free_string_array(naming_failures.n_failures, naming_failures.input_names);
    70         UF_free_string_array(naming_failures.n_failures, naming_failures.output_names);
    71         UF_free(naming_failures.statuses);
    72     }
    73 
    74     //如果存在克隆操作,此例程将终止当前克隆操作,如果没有克隆操作,则不返回错误。 我是“王牌飞行员-里海”欢迎关注我的博客https://www.cnblogs.com/KMould/
    75     UF_CLONE_terminate();
    76 
    77     UF_terminate();
    78 }
    79 
    80 extern int ufusr_ask_unload(void)
    81 {
    82     return (UF_UNLOAD_IMMEDIATELY);
    83 }

     如果有重名的则克隆失败,优化:

     1 #include "Text.h"
     2 extern DllExport void ufsta(char *param, int *returnCode, int rlen)
     3 {
     4     //克隆的7个步骤 我是“王牌飞行员-里海”欢迎关注我的博客https://www.cnblogs.com/KMould/
     5     //    1. UF_CLONE_initialise
     6     //    2. UF_CLONE_add_assembly UF_CLONE_add_part
     7     //    3. UF_CLONE_set_def_action //指定默认的克隆方式
     8     //    4. UF_CLONE_set_name_rule
     9     //    5. UF_CLONE_set_def_directory
    10     //    6. UF_CLONE_perform_clone
    11     //    7. UF_CLONE_terminate
    12 
    13     UF_initialize();
    14 
    15     //初始化一个克隆操作。如果克隆操作已经启动,这个例程将返回UF_CLONE_err_active
    16     UF_CLONE_operation_class_t operation_class = UF_CLONE_clone_operation;
    17     UF_CLONE_initialise(operation_class);
    18 
    19     //UF_CLONE_add_assembly
    20     //此例程将装配添加到当前克隆操作。
    21     //任何加载错误都将放在load_status输出参数中。
    22 
    23     //UF_CLONE_add_part     添加部件到克隆装配中
    24     //此例程将部件添加到当前克隆操作。如果有子部件,则仅引用不克隆子部件
    25 
    26     //     template01.prt
    27     //       |--template01-1.prt
    28     //       |__template01-2.prt
    29 
    30     UF_PART_load_status_t error_status;
    31     string PartPath = "H:\clone\template\template01.prt";
    32     UF_CLONE_add_assembly(PartPath.c_str(), &error_status);
    33     UF_free_string_array(error_status.n_parts, error_status.file_names);
    34     UF_free(error_status.statuses);
    35 
    36     //指定默认的克隆方式
    37     //UF_CLONE_clone    克隆
    38     //UF_CLONE_retain   保持
    39     //UF_CLONE_replace  替换
    40     UF_CLONE_action_t action = UF_CLONE_clone;
    41     UF_CLONE_set_def_action(action);
    42 
    43     //指定默认文件名的方法
    44     UF_CLONE_naming_technique_t naming_technique = UF_CLONE_naming_rule;
    45     UF_CLONE_set_def_naming(naming_technique);
    46 
    47     //初始化命名失败结构,需要在执行前调用
    48     UF_CLONE_naming_failures_t naming_failures;
    49     UF_CLONE_init_naming_failures(&naming_failures);
    50 
    51     //创建或定义克隆部件的存储目录
    52     UF_CLONE_set_def_directory("H:\clone\Part");
    53 
    54     int iAddNum = 0;
    55     int failcode = 1;
    56     int iMaxWhile = 10000;
    57     while (failcode)
    58     {
    59         if (iAddNum > iMaxWhile) break;
    60         iAddNum += 1;
    61         //定义新装配的克隆命名规则
    62         UF_CLONE_name_rule_def_t name_rule;
    63         //UF_CLONE_prepend_string  //加前缀
    64         //UF_CLONE_append_string   //加后缀
    65         //UF_CLONE_replace_string  //替换
    66         //UF_CLONE_rename          //重命名
    67         //前缀
    68         name_rule.type = UF_CLONE_prepend_string;
    69         name_rule.base_string = "";                //如果替换则输入被替换的字符  //如果是加前缀 加后缀则为""
    70         string strNewName= "6666-" + to_string(iAddNum) + "-";
    71         sprintf(name_rule.new_string, "%s", strNewName.c_str());
    72 
    73         UF_CLONE_set_name_rule(&name_rule, &naming_failures);
    74         //执行克隆操作
    75         failcode = UF_CLONE_perform_clone(&naming_failures);
    76     }
    77     
    78     if (naming_failures.n_failures > 0)
    79     {
    80         UF_free_string_array(naming_failures.n_failures, naming_failures.input_names);
    81         UF_free_string_array(naming_failures.n_failures, naming_failures.output_names);
    82         UF_free(naming_failures.statuses);
    83     }
    84     //如果存在克隆操作,此例程将终止当前克隆操作,如果没有克隆操作,则不返回错误。 我是“王牌飞行员-里海”欢迎关注我的博客https://www.cnblogs.com/KMould/
    85     UF_CLONE_terminate();
    86     UF_terminate();
    87 }
    88 
    89 extern int ufusr_ask_unload(void)
    90 {
    91     return (UF_UNLOAD_IMMEDIATELY);
    92 }
  • 相关阅读:
    一致性 hash 算法( consistent hashing )
    UIScrollView的使用2个妙招:键盘遮挡,View 支持滚动
    iphone UI的大小(转)
    XCode 4创建ipa文件及提交应用程序
    我也设计模式——9.Bridge
    3.设计用于浅串行化的类
    我也设计模式——19.Mediator
    我也设计模式——16.Interpreter
    我也设计模式——22.Iterator
    我也设计模式——15.Chain of Responsablity
  • 原文地址:https://www.cnblogs.com/KMould/p/13232972.html
Copyright © 2011-2022 走看看