CoCreate User Forum  

Go Back   CoCreate User Forum > Applications > CoCreate Drafting

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-30-2006, 03:17 AM
pel pel is offline
Registered User
 
Join Date: Sep 2005
Posts: 16
Layers to Parts

I have a lot of Dwg files I want to modify in Me10. All the Geometry is divided in Layers. The splitting is okay, but I want to separate the geometry in Parts.
The name of the Parts should be the same as the name of the Layers. It means that all elements should be moved to a part called the same as the name of the Layer. I start by Smash all the parts, so that I’m sure that everything is in the Top-part. Then I have the LOOP shown below. I’m aware off that the example will only work (If it was working J ) on LINES. But I can’t find any other way to add a selected element to a part. Is there an easier way to do that?
Or does anybody have an idea on why the example is not working.

/Pel



INQ_SELECTED_ELEM GLOBAL ALL

LOOP

LET pt1 (INQ 101)
LET pt2 (INQ 102)
LET x_pt1 (X_OF pt1)
LET x_pt2 (X_OF pt2)
LET y_pt1 (Y_OF pt1)
LET y_pt2 (Y_OF pt2)

LET x_pt ((x_pt2 + x_pt1) *0.5)
LET y_pt ((y_pt2 + y_pt1) *0.5)

LET pt3 (PNT_XY x_pt y_pt)

LET Lag (SUBSTR (INQ 1000) 8 LEN(INQ 1000))
TRAP_ERROR
EDIT_PART ('[' + Lag + ']')
LET Dummy (CHECK_ERROR)

IF (Dummy = 1)
INIT_PART ('[' + Lag + ']')
END_IF

TRAP_ERROR
GATHER pt3

END_PART
END_PART

EXIT_IF (( INQ 14) = 0)
INQ_NEXT_ELEM

END_LOOP

Reply With Quote
  #2  
Old 10-30-2006, 10:45 AM
John Scheffel's Avatar
John Scheffel John Scheffel is offline
Administrator
 
Join Date: Sep 2002
Location: San Jose, CA
Posts: 1,288
Re: Layers to Parts

I didn't try your macro, but one thing that may be missing is PICK_VP_PNT after the GATHER commmand. For example:

GATHER PICK_VP_PNT pt3

When I first read the post I thought this would be easy, but the big problem is that GATHER doesn't seem to support select lists. It only supports picking from a viewport. If GATHER supported select lists it would be easy to gather all the elements in a layer regardess of type. But if you have to pick viewport points you may need to handle each element type that you want to gather individually. Using viewport points is typically a last resort since it can be prone to problems if two elements can be picked from the same point.
__________________
John Scheffel
Reply With Quote
  #3  
Old 10-30-2006, 10:48 PM
Henk Stokkel Henk Stokkel is offline
Registered User
 
Join Date: Aug 2005
Location: Netherlands
Posts: 36
Re: Layers to Parts

We use this code to create parts from geometry with info
In the file Partnaam are all the infos taken from the drawing.
These infos were given by us before the hidden line module was started. So you have to rewrite the code to work in your situation.

succes Henk

LOOP
READ_FILE 1 Partnaam
EXIT_IF (Partnaam = 'END-OF-FILE')
LET Part_id_no (SUBSTR Partnaam 1 (POS Partnaam "]"))
LET Partnaam (SUBSTR Partnaam ((POS Partnaam "]")+1 )
(LEN Partnaam - (POS Partnaam "]")))
CREATE_SUBPART Partnaam INFOS Part_id_no END
CHANGE_ELEM_INFO Part_id_no '' GLOBAL ALL END
END_LOOP
Reply With Quote
  #4  
Old 10-31-2006, 12:05 AM
pel pel is offline
Registered User
 
Join Date: Sep 2005
Posts: 16
Re: Layers to Parts

Hi John
Thank you for your reply.
When i first acquired the job, I said the same as you: It's no problem. But I must admit that it's not that easy anyway. And as you said it's a big problem when you can pick more than one element from the same point. As i can see it, I have to sort all elements, and make different selections.
But i i make a simple drawing with 5 Lines in different layers, it's still not working ! Any help/solutions is welcome.
/Pel
Reply With Quote
  #5  
Old 10-31-2006, 12:09 AM
pel pel is offline
Registered User
 
Join Date: Sep 2005
Posts: 16
Re: Layers to Parts

Hi Henk

I'm not sure i understand what you means . How do you make the file to read in. How do you export INFOS to a file ?

/Pel
Reply With Quote
  #6  
Old 10-31-2006, 12:41 AM
Thom Ivancso's Avatar
Thom Ivancso Thom Ivancso is offline
Registered User
 
Join Date: Oct 2002
Location: Connecticut, USA
Posts: 212
Re: Layers to Parts

Hello Pel,

Could you post your entire macro from DEFINE to END_DEFINE. I would like to see what the entire routine is doing. Would give me a better understanding as to how it works and I might be able to help you.

Cheers
Thom
Reply With Quote
  #7  
Old 10-31-2006, 04:02 AM
pel pel is offline
Registered User
 
Join Date: Sep 2005
Posts: 16
Re: Layers to Parts

Hi Thom

Here is the macro. It's only a rough beta version, an will probaly only work okay with Lines. But it should be okay to test with. And it is in the LOOP something goes wrong. I have also attached a mi file as an example of what i have to convert.

/Pel



DEFINE Convert_Layer_Parts
LOCAL pk1
LOCAL pk2
LOCAL pt1
LOCAL pt2
LOCAL pt3
LOCAL x_pt1
LOCAL x_pt2
LOCAL y_pt1
LOCAL y_pt2
LOCAL Lag
READ PNT
"Pick lower left corner of what you want to convert. (Must be positiv)" pk1
READ PNT
"Pick upper right corner of what you want to convert. (Must be positiv)" pk2
SMASH_SUBPART pk1 pk2
SMASH_SUBPART pk1 pk2
SMASH_SUBPART pk1 pk2

INQ_SELECTED_ELEM pk1 pk2
LOOP
DISPLAY (INQ 14)
LET pt1 (INQ 101)
LET pt2 (INQ 102)
LET x_pt1 (X_OF pt1)
LET x_pt2 (X_OF pt2)
LET y_pt1 (Y_OF pt1)
LET y_pt2 (Y_OF pt2)

LET x_pt ((x_pt2 + x_pt1) *0.5)
LET y_pt ((y_pt2 + y_pt1) *0.5)
LET pt3 (PNT_XY x_pt y_pt)
LET Lag (SUBSTR (INQ 1000) 8 LEN(INQ 1000))
TRAP_ERROR
EDIT_PART ('[' + Lag + ']')
LET Dummy (CHECK_ERROR)
{DISPLAY ( 'LAYER: ' + Lag + ' ' + 'ERROR: ' + STR( Dummy ) )}
IF (Dummy = 1)
INIT_PART ('[' + Lag + ']')
END_IF

TRAP_ERROR
GATHER pt3
END_PART
END_PART
END_PART

EXIT_IF (( INQ 14) = 0)
INQ_NEXT_ELEM
END_LOOP

END_DEFINE
Attached Files
File Type: mi lm600.mi (30.4 KB, 398 views)
Reply With Quote
  #8  
Old 10-31-2006, 10:23 AM
John Scheffel's Avatar
John Scheffel John Scheffel is offline
Administrator
 
Join Date: Sep 2002
Location: San Jose, CA
Posts: 1,288
Re: Layers to Parts

I think the post by Henk contains the key to solving your problem. The CREATE_SUBPART command allows you to create a new subpart under the current part and add elements to it using a select list. You can use this command instead of initializing the part first then using GATHER. Using CREATE_SUBPART you can add all the elements that have the layer INFO attached in one command, you don't need to loop through each element.

I came up with a macro that I think does about 90% of what you need. It worked on an example I created but has some problems with your MI file. Not sure why. But it may give you a good starting point.
Code:
DEFINE Convert_layers_to_parts
  LOCAL Num_g_infos
  LOCAL Count
  LOCAL Info_string
  LOCAL Layer_pos
  LOCAL Layer_name
 
  {Smash everything into the top part}
  EDIT_PART TOP
  LOOP
    INQ_PART CURRENT
    EXIT_IF ((INQ 6) = 0)
    SMASH_SUBPART ALL
  END_LOOP
 
  { Create a logical table of the current global INFO strings  }
  { because the INQ_ENV values change as you create new parts. }
  INQ_ENV 8
  LET Num_g_infos (INQ 3)
  CREATE_LTAB Num_g_infos 1 'G_infos_ltab'
  LET Count 1
  WHILE (Count <= Num_g_infos)
    INQ_ENV 9
    LET Info_string (INQ 302)
    WRITE_LTAB 'G_infos_ltab' Count 1 Info_string
    LET Count (Count+1)
  END_WHILE
 
  {Move all elements with a layer info into a part of the same name}
  LET Count 1
  WHILE (Count <= Num_g_infos)
    LET Info_string (READ_LTAB 'G_infos_ltab' Count 1)
    LET Layer_pos (POS Info_string 'LAYER:')
    IF (Layer_pos)
      LET Layer_name (SUBSTR Info_string (Layer_pos+7) (LEN Info_string-Layer_pos+1))
      DISPLAY ('"'+Layer_name+'"')
      EDIT_PART TOP
      CREATE_SUBPART Layer_name NAMESPACE_INFOS 'SYS:LAYER_SCOPE' ('LAYER: '+Layer_name) END
    END_IF
    LET Count (Count+1)
  END_WHILE
 
  DELETE_LTAB 'G_infos_ltab'
END_DEFINE
__________________
John Scheffel
Reply With Quote
  #9  
Old 10-31-2006, 10:52 PM
pel pel is offline
Registered User
 
Join Date: Sep 2005
Posts: 16
Re: Layers to Parts

Hi John
Your macro does exaxtly what i want. Thank you very much for that. When i read the macro, it looks very simple, but i did not realy think of putting the Infos into an Ltab. But of course this is the right way to do it.
The problem with my mi-file is about the Dimensions from AutoCad. It still put the elements in a part. But it is in Level 2. It's okay, i can move it manually after running the macro.

/Pel
Reply With Quote
  #10  
Old 11-01-2006, 12:22 AM
Thom Ivancso's Avatar
Thom Ivancso Thom Ivancso is offline
Registered User
 
Join Date: Oct 2002
Location: Connecticut, USA
Posts: 212
Re: Layers to Parts

Hello Pel,

Are the entities in your AutoCAD files always on the same layers and is a standard layer named used?

Also are the files of only a single part or are they parts and assemblies?

One thing you might want to look at is in the CoCreate\OSD_Drafting_2005\dxfdwg directory there is a file called dxfdwg.con this file contains the configuration switches for how OSDD loads and translates a dxf/dwg file. Look at the switches under the section titled "# DXF/DWG to MI Translation Switches" the one line you might want to switch to ON is the RecordByLayerInfo switch.

There is a html help file in this directory also that explains all the switches and what they do.

Cheers,
Thom
Reply With Quote
  #11  
Old 11-02-2006, 08:02 PM
pel pel is offline
Registered User
 
Join Date: Sep 2005
Posts: 16
Re: Layers to Parts

Hi Thom

I've looked in the dxfdwg.con file, and tried with different settings. But nothing helps. I think the problem with my files are that dimensions and hatch is in a Layer of its own without any geometry.
/Pel
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 10:40 PM.



Hosted by SureServer    Forums   Modeling FAQ   Macro Site   Vendor/Contractors   Software Resellers   CoCreate   Gallery   Home   Board Members   Regional User Groups  By-Laws  

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.