Looking for some help to loop through imported dxf layers

Looking for some help to loop through imported dxf layers

Anonymous
Not applicable
435 Views
2 Replies
Message 1 of 3

Looking for some help to loop through imported dxf layers

Anonymous
Not applicable

Hi there

 

What I'm trying to do with fusion

  1. Import in dxf's
  2. Extrude them using api

 

What my problem is

I'm not a coder, this is a side project I do in my spare time. I'll show my problem then explain

 

pcb_profiles1 = sketches.item(0).profiles.item(0)

pcb_profiles2 = sketches.item(0).profiles.item(1)

pcb_profiles3 = sketches.item(0).profiles.item(2)

pcb_profiles4 = sketches.item(0).profiles.item(3)

pcb_profiles5= sketches.item(0).profiles.item(4)

pcb_profiles6 = sketches.item(0).profiles.item(5)

pcb_profiles7 = sketches.item(0).profiles.item(6)

pcb_profiles8 = sketches.item(0).profiles.item(7)

 

  • My problem is that this code works for my testing dxf as it has 7 geomtries on the dxf layer, but if I bring in another dxf one that doesn't have 7 geometries on this layer then my code doesn't work

 

What I'm trying to do to fix this problem

 

I would like to be able to loop through the layer so that if I had 1 geometry or 100 geometries the code would work

something along the lines of

 

pcb_profiles1 = sketches.item(0).profiles.item(1)

pcb_profiles+1 = sketches.item(0).profiles.item(+1)

 

I know this isn't the correct way but it shows what I would like

 

Any Help would be much appreciated

0 Likes
436 Views
2 Replies
Replies (2)
Message 2 of 3

JeromeBriot
Mentor
Mentor

Hello,

 

Try:

 

for i in range(0, sketches.item(0).profiles.count):
    profile = sketches.item(0).profiles.item(i)

Or:

for profile in sketches.item(0).profiles:
    profile

 That's the basic idea.

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi Jerome

 

Thank you so much for your fast reply to my problem and I apologise for my reply being so late

 

I'm still having a couple issues with my code and I was hoping if you wouldn't mind having a quick look at them to see if it is anything obvious that I'm doing wrong

 

  • With your first suggestion

 

for i in range(0, sketches.item(0).profiles.count):
    profile = sketches.item(0).profiles.item(i)

 

 

  • My main issue with this was that when I tried to run the code it was asking for the profile to be defined

I attempted a few ways to do this but nothing seemed to work, which is annoying as it seems like such a simple and basic task but this proves my point in that I'm not a proper coder and this is a side project

 

If you have any ideas as to how I could get round this problem I'm all ears

 

  • My first attempt at defining a profile

 

profile = adsk.core.ObjectCollection.create()

 

 

With this I was getting a TypeError: Unsupported Operand type(s) for -: 'ObjectCollection' and 'Profile'

 

I had a look about to see if there was anyone else with this error in hope that they would have a solution to my problem but I couldn't see any but that is probably more me not looking in the correct areas

 

 

  • My second attempt at defining a profile

 

sketch = sketches.add(xyPlane)
profile = sketch.profiles.item(0)

 

 

With this I was getting a TypeError: create()missing 2 required positional arguments: ' Curves' and 'ChainOptions'

 

Again I had a look about to see if there was anyone else out there with this same error and if they had a solution for it but again nothig came of it

 

 

  • If you have any ideas as to how I could fix these issues fire away
for profile in sketches.item(0).profiles:
    profile

 

For your second suggestion

 

 

This one seems more promising as the code runs through with no issues buta few other errors that I haven't encountered before have come up and I'm still working my way through them at the moment

 

 

 

 

 

 

0 Likes